定制 runalyze/php-oauth2-runalyze 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

runalyze/php-oauth2-runalyze

Composer 安装命令:

composer require runalyze/php-oauth2-runalyze

包简介

Runalyze OAuth 2.0 Client Provider for The PHP League OAuth2-Client

README 文档

README

Latest Version Total Downloads

This package provides Runalyze OAuth 2.0 support for the PHP League's OAuth 2.0 Client.

Installation

To install the package, use composer:

composer require runalyze/oauth2-runalyze

Usage

Usage is the same as The League's OAuth client, using \Runalyze\OAuth2\Client\Provider\Runalyze as the provider.

Authorization Code Flow

$provider = new Runalyze\OAuth2\Client\Provider\Runalyze([
    'clientId'          => '{runalyze-client-id}',
    'clientSecret'      => '{runalyze-client-secret}',
    'redirectUri'       => 'https://example.com/callback_url',
]);

// Send OAuth Request
// If we don't have an authorization code then we can get one
$authUrl = $provider->getAuthorizationUrl();
$_SESSION['OAuth2State'] = $provider->getState();

...

// OAuth2 Callback URL
// Compare given state against previously stored one to block CSRF attack
if (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['OAuth2State'])) {

    exit('Invalid state');
    
} else {

    // Try to get an access token
    $token = $provider->getAccessToken('authorization_code', ['code' => $_GET['code']]);

    // Now we can look up users profile
    try {
        // Get the user's details
        $user = $provider->getResourceOwner($token);

        printf('Hello %s!', $user->getName());

    } catch (Exception $e) {
        // Failed to get user details
        exit('Oh no ... ...');
    }

    // We can use token to make other API calls
    echo $token->getToken();
}

Testing

$ ./vendor/bin/phpunit

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-03-21