guix77 / oauth2-steemconnect
为 The PHP League OAuth2-Client 提供的 Steemconnect API v2 OAuth 2.0 客户端提供者
2.2.2
2019-11-05 21:30 UTC
Requires
- league/oauth2-client: ^2.2.1
Requires (Dev)
- mockery/mockery: ~0.9
- phpunit/phpunit: ~4.0
- squizlabs/php_codesniffer: ~2.0
This package is auto-updated.
Last update: 2024-09-06 08:28:44 UTC
README
此包为 PHP League 的 OAuth 2.0 客户端 提供了 Steemconnect API v2 OAuth 2.0 支持。
安装
要安装,请使用 composer
composer require guix77/oauth2-steemconnect
用法
用法与 The League 的 OAuth 客户端相同,使用 \League\OAuth2\Client\Provider\Steemconnect 作为提供者。
授权码流程
$provider = new League\OAuth2\Client\Provider\Steemconnect([ 'clientId' => '{your-steem-app-name}', 'clientSecret' => '{your-steem-app-secret}', 'redirectUri' => 'https://example.com/callback-url', ]); 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'] ]); // Optional: Now you have a token you can look up a users profile data try { // We got an access token, let's now get the user's details $user = $provider->getResourceOwner($token); // Use these details to create a new profile printf('Hello %s!', $user->getNickname()); } catch (Exception $e) { // Failed to get user details exit('Oh dear...'); } // Use this to interact with an API on the users behalf echo $token->getToken(); }
管理作用域
当创建您的 Steemconnect 授权 URL 时,您可以指定您的应用程序可以授权的作用域。
$options = [ 'scope' => ['login', 'post'] // @see https://github.com/steemit/steemconnect/wiki/OAuth-2 ]; $authorizationUrl = $provider->getAuthorizationUrl($options);
如果都没有定义,则提供者将使用内部默认值('login' 作用域)。
测试
$ ./vendor/bin/phpunit
Steemconnect PHP 模块/插件
- Drupal : https://www.drupal.org/project/social_auth_steemconnect(使用此提供者)
- Wordpress : https://github.com/guix77/wordpress-social-login/tree/steemconnect(我已经提交了一个 PR,希望将其包含在优秀的 Wordpress Social Login 插件中,让我们希望它能够进入 Wordpress 插件仓库!)
许可证
MIT 许可证(MIT)。有关更多信息,请参阅 许可证文件。
鸣谢
- Guillaume Duveau
- 从 https://github.com/thephpleague/oauth2-github 调整为 Steemconnect
捐赠
如果您想支持原始开发者和当前维护者,捐赠欢迎至
- Steemit: @guix77 / https://steemit.com/@guix77
- Bitcoin: 12BkpRaeAPcUvxft5yWrSxtknVe7jNUNer
- Ethereum 及基于 Ethereum 的(ERC-20)代币: 0xa32e0e0a0C8Aa10ac70a2827cB20641850824eEc
- Cardano: DdzFFzCqrhsfUhaNNWuV1BSgjXC5ySNMhfPFRASXTkj26qCKoyYSbW3qWzQucuVLU2AE6AzuYiEfgHnc3DwhSyofeqZZxzANVMLBpDxp
- Paypal : guillaume.duveau@gmail.com