edcs/oauth2-mondo

此包已被弃用且不再维护。没有建议的替代包。

OAuth 2.0 客户端 Mondo 提供器

v1.0.3 2016-10-26 04:30 UTC

This package is not auto-updated.

Last update: 2021-02-19 23:47:18 UTC


README

Codeship Status for edcs/oauth-mondo Coverage Status StyleCI SensioLabsInsight

此包为 PHP League 的 OAuth 2.0 客户端 提供Mondo OAuth 2.0 支持。

安装

要安装,请使用 composer

composer require edcs/oauth2-mondo

授权码流程

$provider = new Edcs\OAuth2\Client\Provider\Mondo([
    'clientId'     => '{your-client-id}',
    'clientSecret' => '{your-client-secret}',
    'redirectUri'  => 'https://:8000/',
]);

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

    // If we don't have an authorization code then get one
    $authUrl = $provider->getAuthorizationUrl();
    $_SESSION['oauth2state'] = $provider->getState();
    header('Location: '.$authUrl);
    exit;

// Check given state against previously stored one to mitigate CSRF attack
} elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) {

    unset($_SESSION['oauth2state']);
    exit('Invalid state');

} else {

    // Try to get an access token (using the authorization code grant)
    $token = $provider->getAccessToken('authorization_code', [
        'code' => $_GET['code']
    ]);
    
    // Now you can do something useful with the access token.
    var_dump($token);

    // Optional: Store the token in the session so we can refresh the page while we're testing
    $_SESSION['access_token'] = [
        'access_token'      => $token->getToken(),
        'expires'           => $token->getExpires(),
        'refresh_token'     => $token->getRefreshToken(),
        'resource_owner_id' => $token->getResourceOwnerId()
    ];

    // Optional: Now you have a token you can look up a users profile data
    echo 'Now visit <a href="user.php">this page</a>.';
}

测试

$ ./vendor/bin/phpunit

贡献

有关详细信息,请参阅 CONTRIBUTING

许可

MIT 许可协议 (MIT)。有关更多信息,请参阅 许可文件