Class yii\authclient\OAuth1

Inheritanceyii\authclient\OAuth1 » yii\authclient\BaseOAuth » yii\authclient\BaseClient » yii\base\Component » yii\base\Object
Implementsyii\authclient\ClientInterface, yii\base\Configurable
Subclassesyii\authclient\clients\Twitter
Available since version2.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 http://oauth.net/.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$accessToken array|yii\authclient\OAuthToken yii\authclient\BaseOAuth
$accessTokenMethod string Access token HTTP method. yii\authclient\OAuth1
$accessTokenUrl string OAuth access token URL. yii\authclient\OAuth1
$apiBaseUrl string API base URL. yii\authclient\BaseOAuth
$authUrl string Authorize URL. yii\authclient\BaseOAuth
$behaviors yii\base\Behavior[] List of behaviors attached to this component yii\base\Component
$consumerKey string OAuth consumer key. yii\authclient\OAuth1
$consumerSecret string OAuth consumer secret. yii\authclient\OAuth1
$curlOptions array CURL options. yii\authclient\BaseOAuth
$id string Service id. yii\authclient\ClientInterface
$name string Service name. yii\authclient\ClientInterface
$normalizeUserAttributeMap array Normalize user attribute map. yii\authclient\BaseClient
$requestTokenMethod string Request token HTTP method. yii\authclient\OAuth1
$requestTokenUrl string OAuth request token URL. yii\authclient\OAuth1
$returnUrl string Return URL yii\authclient\BaseOAuth
$scope string Auth request scope. yii\authclient\BaseOAuth
$signatureMethod array|yii\authclient\signature\BaseMethod Signature method instance or its array configuration. yii\authclient\BaseOAuth
$title string Service title. yii\authclient\ClientInterface
$userAttributes array List of user attributes yii\authclient\BaseClient
$version string Protocol version. yii\authclient\OAuth1
$viewOptions array View options in format: optionName => optionValue yii\authclient\BaseClient

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__call() Calls the named method which is not a class method. yii\base\Component
__clone() This method is called after the object is created by cloning an existing one. yii\base\Component
__construct() Constructor. yii\base\Object
__get() Returns the value of a component property. yii\base\Component
__isset() Checks if a property is set, i.e. defined and not null. yii\base\Component
__set() Sets the value of a component property. yii\base\Component
__unset() Sets a component property to be null. yii\base\Component
api() Performs request to the OAuth API. yii\authclient\BaseOAuth
attachBehavior() Attaches a behavior to this component. yii\base\Component
attachBehaviors() Attaches a list of behaviors to the component. yii\base\Component
behaviors() Returns a list of behaviors that this component should behave as. yii\base\Component
buildAuthUrl() Composes user authorization URL. yii\authclient\OAuth1
canGetProperty() Returns a value indicating whether a property can be read. yii\base\Component
canSetProperty() Returns a value indicating whether a property can be set. yii\base\Component
className() Returns the fully qualified name of this class. yii\base\Object
detachBehavior() Detaches a behavior from the component. yii\base\Component
detachBehaviors() Detaches all behaviors from the component. yii\base\Component
ensureBehaviors() Makes sure that the behaviors declared in behaviors() are attached to this component. yii\base\Component
fetchAccessToken() Fetches OAuth access token. yii\authclient\OAuth1
fetchRequestToken() Fetches the OAuth request token. yii\authclient\OAuth1
getAccessToken() yii\authclient\BaseOAuth
getBehavior() Returns the named behavior object. yii\base\Component
getBehaviors() Returns all behaviors attached to this component. yii\base\Component
getCurlOptions() yii\authclient\BaseOAuth
getId() yii\authclient\ClientInterface
getName() yii\authclient\ClientInterface
getNormalizeUserAttributeMap() yii\authclient\BaseClient
getReturnUrl() yii\authclient\BaseOAuth
getSignatureMethod() yii\authclient\BaseOAuth
getTitle() yii\authclient\ClientInterface
getUserAttributes() yii\authclient\ClientInterface
getViewOptions() yii\authclient\ClientInterface
hasEventHandlers() Returns a value indicating whether there is any handler attached to the named event. yii\base\Component
hasMethod() Returns a value indicating whether a method is defined. yii\base\Component
hasProperty() Returns a value indicating whether a property is defined for this component. yii\base\Component
init() Initializes the object. yii\base\Object
off() Detaches an existing event handler from this component. yii\base\Component
on() Attaches an event handler to an event. yii\base\Component
refreshAccessToken() Gets new auth token to replace expired one. yii\authclient\OAuth1
setAccessToken() yii\authclient\BaseOAuth
setCurlOptions() yii\authclient\BaseOAuth
setId() yii\authclient\ClientInterface
setName() yii\authclient\ClientInterface
setNormalizeUserAttributeMap() yii\authclient\BaseClient
setReturnUrl() yii\authclient\BaseOAuth
setSignatureMethod() yii\authclient\BaseOAuth
setTitle() yii\authclient\ClientInterface
setUserAttributes() yii\authclient\BaseClient
setViewOptions() yii\authclient\BaseClient
trigger() Triggers an event. yii\base\Component

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
apiInternal() Performs request to the OAuth API. yii\authclient\OAuth1
composeAuthorizationHeader() Composes authorization header content. yii\authclient\OAuth1
composeRequestCurlOptions() Composes HTTP request CUrl options, which will be merged with the default ones. yii\authclient\OAuth1
composeSignatureBaseString() Creates signature base string, which will be signed by $signatureMethod. yii\authclient\OAuth1
composeSignatureKey() Composes request signature key. yii\authclient\OAuth1
composeUrl() Composes URL from base URL and GET params. yii\authclient\BaseOAuth
convertXmlToArray() Converts XML document to array. yii\authclient\BaseOAuth
createSignatureMethod() Creates signature method instance from its configuration. yii\authclient\BaseOAuth
createToken() Creates token from its configuration. yii\authclient\BaseOAuth
defaultCurlOptions() Returns default cURL options. yii\authclient\BaseOAuth
defaultName() Generates service name. yii\authclient\BaseClient
defaultNormalizeUserAttributeMap() Returns the default $normalizeUserAttributeMap value. yii\authclient\BaseClient
defaultReturnUrl() Composes default $returnUrl value. yii\authclient\OAuth1
defaultTitle() Generates service title. yii\authclient\BaseClient
defaultViewOptions() Returns the default $viewOptions value. yii\authclient\BaseClient
determineContentTypeByHeaders() Attempts to determine HTTP request content type by headers. yii\authclient\BaseOAuth
determineContentTypeByRaw() Attempts to determine the content type from raw content. yii\authclient\BaseOAuth
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\BaseOAuth
getStateKeyPrefix() Returns session key prefix, which is used to store internal states. yii\authclient\BaseOAuth
initUserAttributes() Initializes authenticated user attributes. yii\authclient\BaseClient
mergeCurlOptions() Merge CUrl options. yii\authclient\BaseOAuth
normalizeUserAttributes() Normalize given user attributes according to $normalizeUserAttributeMap. yii\authclient\BaseClient
processResponse() Processes raw response converting it to actual data. yii\authclient\BaseOAuth
removeState() Removes persistent state value. yii\authclient\BaseOAuth
restoreAccessToken() Restores access token. yii\authclient\BaseOAuth
saveAccessToken() Saves token as persistent state. yii\authclient\BaseOAuth
sendRequest() Sends HTTP request. yii\authclient\BaseOAuth
sendSignedRequest() Sends HTTP request, signed by $signatureMethod. yii\authclient\OAuth1
setState() Sets persistent state. yii\authclient\BaseOAuth
signRequest() Sign request with $signatureMethod. yii\authclient\OAuth1

Constants

Hide inherited constants

ConstantValueDescriptionDefined By
CONTENT_TYPE_AUTO 'auto' yii\authclient\BaseOAuth
CONTENT_TYPE_JSON 'json' yii\authclient\BaseOAuth
CONTENT_TYPE_URLENCODED 'urlencoded' yii\authclient\BaseOAuth
CONTENT_TYPE_XML 'xml' yii\authclient\BaseOAuth

Property Details

$accessTokenMethod public property

Access token HTTP method.

$accessTokenUrl public property

OAuth access token URL.

$consumerKey public property

OAuth consumer key.

$consumerSecret public property

OAuth consumer secret.

$requestTokenMethod public property

Request token HTTP method.

$requestTokenUrl public property

OAuth request token URL.

$version public property
string $version '1.0'

Protocol version.

Method Details

apiInternal() protected method

Performs request to the OAuth API.

array apiInternal$accessToken$url$method, array $params, array $headers )
$accessToken yii\authclient\OAuthToken

Actual access token.

$url string

Absolute API URL.

$method string

Request method.

$params array

Request parameters.

$headers array

Additional request headers.

return array

API response.

throws yii\base\Exception

on failure.

buildAuthUrl() public method

Composes user authorization URL.

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\Exception

on failure.

composeAuthorizationHeader() protected method

Composes authorization header content.

string composeAuthorizationHeader( array $params$realm '' )
$params array

Request params.

$realm string

Authorization realm.

return string

Authorization header content.

composeRequestCurlOptions() protected method

Composes HTTP request CUrl options, which will be merged with the default ones.

array composeRequestCurlOptions$method$url, array $params )
$method string

Request type.

$url string

Request URL.

$params array

Request params.

return array

CUrl options.

throws yii\base\Exception

on failure.

composeSignatureBaseString() protected method

Creates signature base string, which will be signed by $signatureMethod.

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.

string composeSignatureKey( )
return string

Signature key.

defaultReturnUrl() protected method

Composes default $returnUrl value.

string defaultReturnUrl( )
return string

Return URL.

fetchAccessToken() public method

Fetches OAuth access token.

yii\authclient\OAuthToken fetchAccessToken( \yii\authclient\OAuthToken $requestToken null$oauthVerifier null, array $params = [] )
$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\Exception

on failure.

fetchRequestToken() public method

Fetches the OAuth request token.

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.

array generateCommonRequestParams( )
return array

Common request params.

generateNonce() protected method

Generates nonce value.

string generateNonce( )
return string

Nonce value.

generateTimestamp() protected method

Generates timestamp.

integer generateTimestamp( )
return integer

Timestamp.

refreshAccessToken() public method

Gets new auth token to replace expired one.

yii\authclient\OAuthToken refreshAccessToken( \yii\authclient\OAuthToken $token )
$token yii\authclient\OAuthToken

Expired auth token.

return yii\authclient\OAuthToken

New auth token.

sendSignedRequest() protected method

Sends HTTP request, signed by $signatureMethod.

array sendSignedRequest$method$url, array $params = [], array $headers = [] )
$method string

Request type.

$url string

Request URL.

$params array

Request params.

$headers array

Additional request headers.

return array

Response.

signRequest() protected method

Sign request with $signatureMethod.

array signRequest$method$url, array $params )
$method string

Request method.

$url string

Request URL.

$params array

Request params.

return array

Signed request params.