psecio/oauth2-discord 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

psecio/oauth2-discord

Composer 安装命令:

composer require psecio/oauth2-discord

包简介

A Discord provider for the League Oauth2 client

README 文档

README

Discord OAuth2 Provider

This is a Discord provider for use with the PHP League's OAuth2 client.

Installation

To install the provider use Composer:

composer require psecio/oauth2-discord

Usage: OAuth Connection

The code below is an example of how to use the library to make an OAuth connection to the Discord service, authorizing it for your account. By default it will request these scopes:

  • identity
  • email
  • messages.read
  • guilds

See this documentation for more about scopes.

<?php

$provider = new \League\OAuth2\Client\Provider\Discord([
    'clientId'          => 'client-id',
    'clientSecret'      => 'client-secret',
    'redirectUri'       => 'http://yoursite.com/callback'
]);

if (!isset($_GET['code'])) {
    // If we don't have a code yet, we need to make the link
    echo '<a href="'.$provider->getAuthorizationUrl().'">Link to Discord</a>';

} else {
    // If we do have a code, use it to get a token
    $accessToken = $provider->getAccessToken('authorization_code', [
        'code' => $_GET['code']
    ]);

    $user = $provider->getResourceOwner($accessToken);

    /**
     * User object contains:
     * - username
     * - verified
     * - mfa_enabled
     * - id
     * - avatar
     */
}

?>

Usage: Getting Data

This library can also be used to get information from the API once an authenticated request has been made. This process requires a class that implements the Psecio\DiscordPHP\ConnectorInterface and defines a getToken() method. This method should return the current OAuth2 token and can then be used with the Manager class. For example:

<?php
class MyConnector implements \Psecio\DiscordPHP\ConnectorInterface
{
    public function getToken()
    {
        return 'fdagahdar4324fdgfdsgfss';
    }
}

$connector = new MyConnector();
$manager = \Psecio\DiscordPHP\Manager::getInstance($connector);

?>

If all goes well (and the token isn't expired or anything odd like that) you should now be able to get information from the API using helper methods. For example, to get all of the guilds for the currently linked user, you can just use the guilds property:

<?php
$guilds = $manager->guilds;
foreach ($guilds as $guild) {
    echo $guild->name;
}

?>

Supported properties

  • guilds: list of current user's guilds
  • user: information about the current user

统计信息

  • 总下载量: 2.78k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-10-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固