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

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

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

romitou/oauth2-discord

Composer 安装命令:

composer require romitou/oauth2-discord

包简介

This package provides Discord's OAuth 2 and supports League's OAuth 2.0 client.

README 文档

README

This package provides Discord's OAuth 2 and supports League's OAuth 2.0 client.


🚀 Download and installation

This package is available on Packagist. You can install it directly via Composer with the command composer req romitou/oauth2-discord.

📖 Example

<?php

require __DIR__ . '/vendor/autoload.php';
session_start();

$discordProvider = new \Romitou\OAuth2\Client\DiscordProvider([
    'clientId' => '', // The ID of your application
    'clientSecret' => '', // The secret of your application
    'redirectUri' => '', // The callback URI where the user will be redirected
    'scopes' => [], // The scopes you want (e.g. ['identify', 'email'])
    'state' => '' // Optional, the state of the provider
]);

if (isset($_GET['code'])) {

    if ($_SESSION['oauth2_state'] !== $_GET['state'])
        exit('The returned state doesn\'t match with your local state.');
        
    $discordToken = $discordProvider->getAccessToken('authorization_code', [
        'code' => $_GET['code']
    ]);
    
    $discordUser = $discordProvider->getResourceOwner($discordToken);
    
    // Now, you will be able to retrieve user's informations.
    echo 'Your token is ' . $discordToken->getToken();
    echo 'Your username is ' . $discordUser->getUsername();
    
} else {

    $oauthUrl = $discordProvider->getAuthorizationUrl();
    $_SESSION['oauth2_state'] = $discordProvider->getState();
    header('Location: ' . $oauthUrl);
    
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-3.0-only
  • 更新时间: 2021-01-03

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固