healyhatman/oauth2-keypay

OAuth 2 客户端提供者

1.1 2022-06-29 03:53 UTC

This package is auto-updated.

Last update: 2024-09-29 05:49:11 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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

安装

您可以通过 composer 安装此包

composer require healyhatman/oauth2-keypay

用法

用法与 The League 的 OAuth 客户端相同,使用 \Healyhatman\OAuth2\Client\Provider\KeyPay 作为提供者。

授权码流

session_start();

$provider = new \Healyhatman\Oauth2\Client\Provider\KeyPay([
    'clientId'     => '{your KeyPay client ID}',
    'clientSecret' => '{your KeyPay client secret}',
    'clientId'     => '{your KeyPay redirect URI}'
]);

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

    // If we don't have an authorization code then get one
    $authUrl = $provider->getAuthorizationUrl(['scope' => '']);

    $_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']
    ]);
}

然后您可以存储令牌以发出请求

刷新令牌

$newAccessToken = $provider->getAccessToken('refresh_token', [
    'refresh_token' => $access->refresh_token
]);

测试

我还没有为这个做任何事情。也许有一天!

贡献

请参阅 CONTRIBUTING 以获取详细信息。

安全漏洞

请查看我们关于如何报告安全漏洞的安全策略 我们的安全策略

鸣谢

特别感谢

许可协议

MIT 许可协议(MIT)。请参阅 许可文件 获取更多信息。