stevenmaguire / oauth2-paypal
PHP League OAuth2-Client 的 Paypal OAuth 2.0 客户端提供程序
2.0.0
2017-01-26 02:39 UTC
Requires
- league/oauth2-client: ^2.0
Requires (Dev)
- mockery/mockery: ~0.9
- phpunit/phpunit: ~4.0
- squizlabs/php_codesniffer: ~2.0
This package is auto-updated.
Last update: 2024-09-14 10:49:01 UTC
README
此包为 PHP League 的 OAuth 2.0 客户端 提供Paypal OAuth 2.0 支持。
安装
要安装,请使用 composer
composer require stevenmaguire/oauth2-paypal
用法
用法与 The League 的 OAuth 客户端相同,使用 \Stevenmaguire\OAuth2\Client\Provider\Paypal
作为提供程序。
授权码流
$provider = new Stevenmaguire\OAuth2\Client\Provider\Paypal([ 'clientId' => '{paypal-client-id}', 'clientSecret' => '{paypal-client-secret}', 'redirectUri' => 'https://example.com/callback-url', 'isSandbox' => true, // Optional, defaults to false. When true, client uses sandbox urls. ]);
有关此包的进一步使用,请参阅 核心包文档中的“授权码授予”部分。
在授权请求中管理作用域
$options = [ 'scope' => ['openid', 'profile', 'email', 'phone', 'address'] ]; $authorizationUrl = $provider->getAuthorizationUrl($options);
传递的值必须始终包含至少
openid
您可以在 PayPal 网站上查看 作用域的完整列表。
刷新令牌
$provider = new Stevenmaguire\OAuth2\Client\Provider\Paypal([ 'clientId' => '{paypal-client-id}', 'clientSecret' => '{paypal-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)。请参阅 许可文件 了解更多信息。