PHP Class yii\authclient\OAuth1

In order to acquire access token perform following sequence: ~~~ use yii\authclient\OAuth1; $oauthClient = new OAuth1(); $requestToken = $oauthClient->fetchRequestToken(); // Get request token $url = $oauthClient->buildAuthUrl($requestToken); // Get authorization URL return Yii::$app->getResponse()->redirect($url); // Redirect to authorization URL After user returns at our site: $accessToken = $oauthClient->fetchAccessToken($requestToken); // Upgrade to access token ~~~
See also: http://oauth.net/
Since: 2.0
Author: Paul Klimov ([email protected])
Inheritance: extends BaseOAuth
Show file Open project: yiisoft/yii2-authclient Class Usage Examples

Public Properties

Property Type Description
$accessTokenMethod access token HTTP method.
$accessTokenUrl OAuth access token URL.
$authorizationHeaderMethods list of the request methods, which require adding 'Authorization' header. By default only POST requests will have 'Authorization' header. You may set this option to null in order to make all requests to use 'Authorization' header.
$consumerKey OAuth consumer key.
$consumerSecret OAuth consumer secret.
$requestTokenMethod request token HTTP method.
$requestTokenUrl OAuth request token URL.
$version protocol version.

Public Methods

Method Description
applyAccessTokenToRequest ( $request, $accessToken )
beforeRequestSend ( RequestEvent $event ) Handles [[Request::EVENT_BEFORE_SEND]] event.
buildAuthUrl ( OAuthToken $requestToken = null, array $params = [] ) : string Composes user authorization URL.
createApiRequest ( )
createRequest ( )
fetchAccessToken ( string $oauthToken = null, OAuthToken $requestToken = null, string $oauthVerifier = null, array $params = [] ) : OAuthToken Fetches OAuth access token.
fetchRequestToken ( array $params = [] ) : OAuthToken Fetches the OAuth request token.
refreshAccessToken ( OAuthToken $token ) : OAuthToken Gets new auth token to replace expired one.
signRequest ( Request $request, OAuthToken | null $token = null ) Sign given request with [[signatureMethod]].

Protected Methods

Method Description
composeAuthorizationHeader ( array $params, string $realm = '' ) : array Composes authorization header.
composeSignatureBaseString ( string $method, string $url, array $params ) : string Creates signature base string, which will be signed by [[signatureMethod]].
composeSignatureKey ( OAuthToken | null $token = null ) : string Composes request signature key.
defaultReturnUrl ( ) : string Composes default [[returnUrl]] value.
generateCommonRequestParams ( ) : array Generate common request params like version, timestamp etc.
generateNonce ( ) : string Generates nonce value.
generateTimestamp ( ) : integer Generates timestamp.

Method Details

applyAccessTokenToRequest() public method

public applyAccessTokenToRequest ( $request, $accessToken )

beforeRequestSend() public method

Ensures every request has been signed up before sending.
Since: 2.1
public beforeRequestSend ( RequestEvent $event )
$event yii\httpclient\RequestEvent event instance.

buildAuthUrl() public method

Composes user authorization URL.
public buildAuthUrl ( OAuthToken $requestToken = null, array $params = [] ) : string
$requestToken OAuthToken OAuth request token.
$params array additional request params.
return string authorize URL

composeAuthorizationHeader() protected method

Composes authorization header.
protected composeAuthorizationHeader ( array $params, string $realm = '' ) : array
$params array request params.
$realm string authorization realm.
return array authorization header in format: [name => content].

composeSignatureBaseString() protected method

Creates signature base string, which will be signed by [[signatureMethod]].
protected composeSignatureBaseString ( string $method, string $url, array $params ) : string
$method string request method.
$url string request URL.
$params array request params.
return string base signature string.

composeSignatureKey() protected method

Composes request signature key.
protected composeSignatureKey ( OAuthToken | null $token = null ) : string
$token OAuthToken | null OAuth token to be used for signature key.
return string signature key.

createApiRequest() public method

public createApiRequest ( )

createRequest() public method

public createRequest ( )

defaultReturnUrl() protected method

Composes default [[returnUrl]] value.
protected defaultReturnUrl ( ) : string
return string return URL.

fetchAccessToken() public method

Fetches OAuth access token.
public fetchAccessToken ( string $oauthToken = null, OAuthToken $requestToken = null, string $oauthVerifier = null, array $params = [] ) : OAuthToken
$oauthToken string OAuth token returned with redirection back to client.
$requestToken OAuthToken OAuth request token.
$oauthVerifier string OAuth verifier.
$params array additional request params.
return OAuthToken OAuth access token.

fetchRequestToken() public method

Fetches the OAuth request token.
public fetchRequestToken ( array $params = [] ) : OAuthToken
$params array additional request params.
return OAuthToken request token.

generateCommonRequestParams() protected method

Generate common request params like version, timestamp etc.
protected generateCommonRequestParams ( ) : array
return array common request params.

generateNonce() protected method

Generates nonce value.
protected generateNonce ( ) : string
return string nonce value.

generateTimestamp() protected method

Generates timestamp.
protected generateTimestamp ( ) : integer
return integer timestamp.

refreshAccessToken() public method

Gets new auth token to replace expired one.
public refreshAccessToken ( OAuthToken $token ) : OAuthToken
$token OAuthToken expired auth token.
return OAuthToken new auth token.

signRequest() public method

Sign given request with [[signatureMethod]].
Since: 2.1 this method is public.
public signRequest ( Request $request, OAuthToken | null $token = null )
$request yii\httpclient\Request request instance.
$token OAuthToken | null OAuth token to be used for signature, if not set [[accessToken]] will be used.

Property Details

$accessTokenMethod public property

access token HTTP method.
public $accessTokenMethod

$accessTokenUrl public property

OAuth access token URL.
public $accessTokenUrl

$authorizationHeaderMethods public property

list of the request methods, which require adding 'Authorization' header. By default only POST requests will have 'Authorization' header. You may set this option to null in order to make all requests to use 'Authorization' header.
Since: 2.1.1
public $authorizationHeaderMethods

$consumerKey public property

OAuth consumer key.
public $consumerKey

$consumerSecret public property

OAuth consumer secret.
public $consumerSecret

$requestTokenMethod public property

request token HTTP method.
public $requestTokenMethod

$requestTokenUrl public property

OAuth request token URL.
public $requestTokenUrl

$version public property

protocol version.
public $version