poirot / client-oauth2
该软件包最新版本(dev-devel)没有可用的许可证信息。
为与OAuth 2.0服务器提供者集成提供简单且清晰的抽象。
dev-devel
2019-01-07 12:04 UTC
Requires
- poirot/api-client: dev-devel
- poirot/ioc: dev-devel
- poirot/std: dev-devel
- psr/http-message: 1.0
Suggests
- poirot/mod-authorization: Integrated Authentication Mechanism Based On Tokens.
- poirot/psr7-http: PSR-7 HTTP Implementation.
This package is auto-updated.
Last update: 2024-09-08 07:29:05 UTC
README
为与OAuth 2.0服务器提供者集成提供简单且清晰的抽象。
配置客户端
$auth = new \Poirot\OAuth2Client\Client( 'http://172.17.0.1:8000/' , 'test@default.axGEceVCtGqZAdW3rc34sqbvTASSTZxD' , 'xPWIpmzBK38MmDRd' );
检索隐式URL重定向
$url = $auth->attainAuthorizationUrl( $auth->withGrant('implicit') );
授权码授权
检索重定向到授权URL
$url = $auth->attainAuthorizationUrl( $auth->withGrant(GrantPlugins::AUTHORIZATION_CODE) );
当用户重定向回包含授权码时
/** @var iAccessTokenObject $token */ $token = $auth->attainAccessToken( $auth->withGrant(GrantPlugins::AUTHORIZATION_CODE, ['code' => 'your_auth_code']) ); $token->getAccessToken(); $token->getScopes(); $token->getDateTimeExpiration(); // ...
客户端凭据授权
覆盖默认作用域请求
$token = $auth->attainAccessToken( $auth->withGrant(GrantPlugins::CLIENT_CREDENTIALS, [ 'scopes' => ['override' ,'scopes'] ]) );
密码凭据
将特定参数作为参数传递给授权工厂
try { $auth->attainAccessToken( $auth->withGrant('password') ); } catch (\Poirot\OAuth2Client\Exception\exMissingGrantRequestParams $e) { // Request Param "username" & "password" must Set. echo $e->getMessage(); $token = $token = $auth->attainAccessToken( $auth->withGrant('password', ['username' => 'payam', 'password' => '123456']) ); $refreshTokenStr = $token->getRefreshToken(); }
等等...
Poirot-OAuth2服务器联合命令
特定Poirot服务器联合命令,用于处理第三方应用程序与服务器。
! 对于联合调用,我们需要有效的令牌:此令牌可以严格定义为客户端或从服务器检索。
以下示例显示了在需要时从OAuth服务器断言的令牌!
// Setup OAuth2 Client $client = new \Poirot\OAuth2Client\Client( 'http://172.17.0.1:8000/' , 'test@default.axGEceVCtGqZAdW3rc34sqbvTASSTZxD' , 'xPWIpmzBK38MmDRd' ); // Token Provider for Federation Calls // Use Credential Grant as Grant Type for Tokens $tokenProvider = new TokenFromOAuthClient( $client , $client->withGrant('client_credentials') ); // Note: // Make Calls and Don`t Worry About Token Renewal And Expired Tokens. // Platfrom Will Handle It. $federation = new \Poirot\OAuth2Client\Federation( 'http://172.17.0.1:8000/' , $tokenProvider ); // Check wheather this identifier(s) is given by any user? $checkExists = $federation->checkIdentifierGivenToAnyUser([ 'email' => 'naderi.payam@gmail.com', 'mobile' => [ 'number' => '9355497674', 'country' => '+98', ], ]);