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.
Access token HTTP method.
public string $accessTokenMethod = 'GET'
OAuth access token URL.
public string $accessTokenUrl = null
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']
OAuth consumer key.
public string $consumerKey = null
OAuth consumer secret.
public string $consumerSecret = null
Request token HTTP method.
public string $requestTokenMethod = 'GET'
OAuth request token URL.
public string $requestTokenUrl = null
Protocol version.
public string $version = '1.0'
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. |
© 2008–2017 by Yii Software LLC
Licensed under the three clause BSD license.
http://www.yiiframework.com/doc-2.0/yii-authclient-oauth1.html