On this page
Abstract Class yii\authclient\OAuth1
Inheritance | yii\authclient\OAuth1 » yii\authclient\BaseOAuth » yii\authclient\BaseClient » yii\base\Component » yii\base\Object |
---|---|
Implements | yii\authclient\ClientInterface, yii\base\Configurable |
Subclasses | yii\authclient\clients\Twitter |
Available since version | 2.0 |
Source Code | https://github.com/yiisoft/yii2-authclient/blob/master/OAuth1.php |
OAuth1 serves as a client for the OAuth 1/1.0a flow.
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 https://oauth.net/1/ https://tools.ietf.org/html/rfc5849.
Public Properties
Public Methods
Protected Methods
Property Details
$accessTokenMethod public property
Access token HTTP method.
public string $accessTokenMethod = 'GET'
$accessTokenUrl public property
OAuth access token URL.
public string $accessTokenUrl = null
$authorizationHeaderMethods public property (available since version 2.1.1)
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.
public array|null $authorizationHeaderMethods = ['POST']
$consumerKey public property
OAuth consumer key.
public string $consumerKey = null
$consumerSecret public property
OAuth consumer secret.
public string $consumerSecret = null
$requestTokenMethod public property
Request token HTTP method.
public string $requestTokenMethod = 'GET'
$requestTokenUrl public property
OAuth request token URL.
public string $requestTokenUrl = null
$version public property
Protocol version.
public string $version = '1.0'
Method Details
applyAccessTokenToRequest() public method
Applies access token to the HTTP request instance.
public void applyAccessTokenToRequest ( $request, $accessToken ) | ||
---|---|---|
$request | yii\httpclient\Request | HTTP request instance. |
$accessToken | yii\authclient\OAuthToken | Access token instance. |
beforeRequestSend() public method (available since version 2.1)
Handles yii\httpclient\Request::EVENT_BEFORE_SEND event.
Ensures every request has been signed up before sending.
public void beforeRequestSend ( $event ) | ||
---|---|---|
$event | yii\httpclient\RequestEvent | Event instance. |
buildAuthUrl() public method
Composes user authorization URL.
public string buildAuthUrl ( yii\authclient\OAuthToken $requestToken = null, array $params = [] ) | ||
---|---|---|
$requestToken | yii\authclient\OAuthToken | OAuth request token. |
$params | array | Additional request params. |
return | string | Authorize URL |
throws | yii\base\InvalidParamException | on failure. |
composeAuthorizationHeader() protected method
Composes authorization header.
protected array composeAuthorizationHeader ( array $params, $realm = '' ) | ||
---|---|---|
$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 string composeSignatureBaseString ( $method, $url, array $params ) | ||
---|---|---|
$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 string composeSignatureKey ( $token = null ) | ||
---|---|---|
$token | yii\authclient\OAuthToken|null | OAuth token to be used for signature key. |
return | string | Signature key. |
createApiRequest() public method
Creates an HTTP request for the API call.
The created request will be automatically processed adding access token parameters and signature before sending. You may use createRequest() to gain full control over request composition and execution.
public yii\httpclient\Request createApiRequest ( ) | ||
---|---|---|
return | yii\httpclient\Request | HTTP request instance. |
createRequest() public method
Creates HTTP request instance.
public yii\httpclient\Request createRequest ( ) | ||
---|---|---|
return | yii\httpclient\Request | HTTP request instance. |
defaultReturnUrl() protected method
Composes default $returnUrl value.
protected string defaultReturnUrl ( ) | ||
---|---|---|
return | string | Return URL. |
fetchAccessToken() public method
Fetches OAuth access token.
public yii\authclient\OAuthToken fetchAccessToken ( $oauthToken = null, yii\authclient\OAuthToken $requestToken = null, $oauthVerifier = null, array $params = [] ) | ||
---|---|---|
$oauthToken | string | OAuth token returned with redirection back to client. |
$requestToken | yii\authclient\OAuthToken | OAuth request token. |
$oauthVerifier | string | OAuth verifier. |
$params | array | Additional request params. |
return | yii\authclient\OAuthToken | OAuth access token. |
throws | yii\base\InvalidParamException | on failure. |
throws | yii\web\HttpException | in case oauth token miss-matches request token. |
fetchRequestToken() public method
Fetches the OAuth request token.
public yii\authclient\OAuthToken fetchRequestToken ( array $params = [] ) | ||
---|---|---|
$params | array | Additional request params. |
return | yii\authclient\OAuthToken | Request token. |
generateCommonRequestParams() protected method
Generate common request params like version, timestamp etc.
protected array generateCommonRequestParams ( ) | ||
---|---|---|
return | array | Common request params. |
generateNonce() protected method
Generates nonce value.
protected string generateNonce ( ) | ||
---|---|---|
return | string | Nonce value. |
generateTimestamp() protected method
Generates timestamp.
protected integer generateTimestamp ( ) | ||
---|---|---|
return | integer | Timestamp. |
refreshAccessToken() public method
Gets new auth token to replace expired one.
public yii\authclient\OAuthToken refreshAccessToken ( yii\authclient\OAuthToken $token ) | ||
---|---|---|
$token | yii\authclient\OAuthToken | Expired auth token. |
return | yii\authclient\OAuthToken | New auth token. |
signRequest() public method (available since version 2.1)
Sign given request with $signatureMethod.
public void signRequest ( $request, $token = null ) | ||
---|---|---|
$request | yii\httpclient\Request | Request instance. |
$token | yii\authclient\OAuthToken|null | OAuth token to be used for signature, if not set $accessToken will be used. |
© 2008–2017 by Yii Software LLC
Licensed under the three clause BSD license.
http://www.yiiframework.com/doc-2.0/yii-authclient-oauth1.html