PHP Classes

PHP OAuth2 Client: Authorize and access servers using OAuth2

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 207 All time: 8,406 This week: 524Up
Version License PHP version Categories
client-oauth2 1.0.0MIT/X Consortium ...5PHP 5, User Management, Web services
Description 

Author

This package can authorize and access servers using OAuth2.

It can access given OAuth 2.0 servers supporting several methods to obtain tokens to access OAuth 2.0 servers like AUTHORIZATION_CODE and CLIENT_CREDENTIALS.

Subclasses of the client classes can make calls to specific OAuth 2.0 server APIs using the tokens obtained previous.

Picture of Payam Naderi
  Performance   Level  
Innovation award
Innovation award
Nominee: 2x

 

Documentation

Client-OAuth2

Provides a simple and clean Abstraction for Integration with OAuth 2.0 Server Providers.

Config Client

$auth = new \Poirot\OAuth2Client\Client(
    'http://172.17.0.1:8000/'
    , 'test@default.axGEceVCtGqZAdW3rc34sqbvTASSTZxD'
    , 'xPWIpmzBK38MmDRd'
);

Retrieve Implicit Url Redirection

$url = $auth->attainAuthorizationUrl( $auth->withGrant('implicit') );

Authorization Code Grant

Retrieve Redirection To Authorize Url:

$url = $auth->attainAuthorizationUrl( $auth->withGrant(GrantPlugins::AUTHORIZATION_CODE) );

When User redirect back include Auth Code:

/ @var iAccessTokenObject $token */
$token = $auth->attainAccessToken(
    $auth->withGrant(GrantPlugins::AUTHORIZATION_CODE, ['code' => 'your_auth_code'])
);

$token->getAccessToken();
$token->getScopes();
$token->getDateTimeExpiration();
// ...

Client Credential Grant

override default scopes request

$token = $auth->attainAccessToken(
    $auth->withGrant(GrantPlugins::CLIENT_CREDENTIALS, [ 'scopes' => ['override' ,'scopes'] ])
);

Password Credential

Specific Params Passed As Argument To Grant Factory

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();
}

And So on ....

Poirot-OAuth2 Server Federation Commands

Specific Poirot Server Federation Commands To Deal 3rd party application with Server.

! For Federation Calls we need valid token: this token can strictly defined to client or retrieve from server.

example below show token asserted from oauth server when required!


// 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',
    ],
]);


  Files folder image Files (75)  
File Role Description
Files folder imagemod (2 files, 5 directories)
Files folder imagesrc (3 files, 7 directories)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:207
This week:0
All time:8,406
This week:524Up