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
Method | Description | Defined By |
---|---|---|
composeAuthorizationHeader() | Composes authorization header. | yii\authclient\OAuth1 |
composeSignatureBaseString() | Creates signature base string, which will be signed by \yii\authclient\signatureMethod. | yii\authclient\OAuth1 |
composeSignatureKey() | Composes request signature key. | yii\authclient\OAuth1 |
composeUrl() | Composes URL from base URL and GET params. | yii\authclient\BaseOAuth |
createHttpClient() | {@inheritdoc} | yii\authclient\BaseOAuth |
createSignatureMethod() | Creates signature method instance from its configuration. | yii\authclient\BaseOAuth |
createToken() | Creates token from its configuration. | yii\authclient\BaseOAuth |
defaultName() | Generates service name. | yii\authclient\BaseClient |
defaultNormalizeUserAttributeMap() | Returns the default \yii\authclient\normalizeUserAttributeMap value. | yii\authclient\BaseClient |
defaultRequestOptions() | {@inheritdoc} | yii\authclient\BaseOAuth |
defaultReturnUrl() | Composes default \yii\authclient\returnUrl value. | yii\authclient\BaseOAuth |
defaultTitle() | Generates service title. | yii\authclient\BaseClient |
defaultViewOptions() | Returns the default \yii\authclient\viewOptions value. | yii\authclient\BaseClient |
generateCommonRequestParams() | Generate common request params like version, timestamp etc. | yii\authclient\OAuth1 |
generateNonce() | Generates nonce value. | yii\authclient\OAuth1 |
generateTimestamp() | Generates timestamp. | yii\authclient\OAuth1 |
getState() | Returns persistent state value. | yii\authclient\BaseClient |
getStateKeyPrefix() | Returns session key prefix, which is used to store internal states. | yii\authclient\BaseClient |
initUserAttributes() | Initializes authenticated user attributes. | yii\authclient\BaseClient |
normalizeUserAttributes() | Normalize given user attributes according to \yii\authclient\normalizeUserAttributeMap. | yii\authclient\BaseClient |
removeState() | Removes persistent state value. | yii\authclient\BaseClient |
restoreAccessToken() | Restores access token. | yii\authclient\BaseOAuth |
saveAccessToken() | Saves token as persistent state. | yii\authclient\BaseOAuth |
sendRequest() | Sends the given HTTP request, returning response data. | yii\authclient\BaseOAuth |
setState() | Sets persistent state. | yii\authclient\BaseClient |
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
{@inheritdoc}
public void applyAccessTokenToRequest ( $request, $accessToken ) | ||
$request | ||
$accessToken |
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 \yii\authclient\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. |
---|
{@inheritdoc}
public void createApiRequest ( ) |
{@inheritdoc}
public void createRequest ( ) |
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 \yii\authclient\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 \yii\authclient\accessToken will be used. |