netliferesearch/oauth2-twist

PHP League OAuth2-Client 的 Twist OAuth 2.0 客户端提供者

1.0.1 2017-10-27 11:17 UTC

This package is not auto-updated.

Last update: 2024-09-29 04:42:59 UTC


README

本包为 PHP League 的 OAuth 2.0 客户端提供 Twist OAuth 2.0 支持。

安装

要安装,请使用 composer

composer require netliferesearch/oauth2-twist

使用方法

使用方法与 League 的 OAuth 客户端相同,使用 \Netliferesearch\OAuth2\Client\Provider\Twist 作为提供者。

授权码流

$provider = new Netliferesearch\OAuth2\Client\Provider\Twist([
    'clientId'          => '{twist-client-id}',
    'clientSecret'      => '{twist-client-secret}',
    'redirectUri'       => 'https://example.com/callback-url'
]);

有关本包的进一步使用,请参阅核心包关于“授权码授予”的文档

刷新令牌

一旦您的应用程序被授权,您可以使用刷新令牌而不是通过获取全新令牌的整个流程来刷新过期令牌。为此,只需从您的数据存储中重新使用此刷新令牌来请求刷新。

$existingAccessToken = getAccessTokenFromYourDataStore();

if ($existingAccessToken->hasExpired()) {
    $newAccessToken = $provider->getAccessToken('refresh_token', [
        'refresh_token' => $existingAccessToken->getRefreshToken()
    ]);

    // Purge old access token and store new access token to your data store.
}

有关本包的进一步使用,请参阅核心包关于“刷新令牌”的文档

测试

$ ./vendor/bin/phpunit

贡献

请参阅CONTRIBUTING 获取详细信息。

致谢

许可协议

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