Abstract Class yii\authclient\OAuth1
Inheritance | yii\authclient\OAuth1 » yii\authclient\BaseOAuth » yii\authclient\BaseClient » yii\base\Component » yii\base\BaseObject |
---|---|
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;
use Yii;
// assuming class MyAuthClient extends OAuth1
$oauthClient = new MyAuthClient();
$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(Yii::$app->request->get('oauth_token'), $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
Access token HTTP method.
OAuth access token URL.
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.
OAuth consumer key.
OAuth consumer secret.
Request token HTTP method.
OAuth request token URL.
Protocol version.
Method Details
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. |
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. |
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. |
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]. |
---|
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. |
---|
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. |
---|
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. |
---|
Creates HTTP request instance.
public yii\httpclient\Request createRequest ( ) | ||
return | yii\httpclient\Request | HTTP request instance. |
---|
Composes default $returnUrl value.
protected string defaultReturnUrl ( ) | ||
return | string | Return URL. |
---|
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. |
Fetches the OAuth request token.
public yii\authclient\OAuthToken fetchRequestToken ( array $params = [] ) | ||
$params | array | Additional request params. |
return | yii\authclient\OAuthToken | Request token. |
---|
Generate common request params like version, timestamp etc.
protected array generateCommonRequestParams ( ) | ||
return | array | Common request params. |
---|
Generates nonce value.
protected string generateNonce ( ) | ||
return | string | Nonce value. |
---|
Generates timestamp.
protected integer generateTimestamp ( ) | ||
return | integer | Timestamp. |
---|
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. |
---|
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. |