Class yii\authclient\clients\Twitter

Inheritanceyii\authclient\clients\Twitter » yii\authclient\OAuth1 » yii\authclient\BaseOAuth » yii\authclient\BaseClient » yii\base\Component » yii\base\BaseObject
Implementsyii\authclient\ClientInterface, yii\base\Configurable
Available since version2.0
Source Code https://github.com/yiisoft/yii2-authclient/blob/master/clients/Twitter.php

Twitter allows authentication via Twitter OAuth.

In order to use Twitter OAuth you must register your application at https://dev.twitter.com/apps/new.

Example application configuration:

'components' => [
    'authClientCollection' => [
        'class' => 'yii\authclient\Collection',
        'clients' => [
            'twitter' => [
                'class' => 'yii\authclient\clients\Twitter',
                'attributeParams' => [
                    'include_email' => 'true'
                ],
                'consumerKey' => 'twitter_consumer_key',
                'consumerSecret' => 'twitter_consumer_secret',
            ],
        ],
    ]
    // ...
]

Note: some auth workflows provided by Twitter, such as application-only authentication, uses OAuth 2 protocol and thus are impossible to be used with this class. You should use yii\authclient\clients\TwitterOAuth2 for these.

See also:

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$accessTokenMethod {@inheritdoc} yii\authclient\clients\Twitter
$accessTokenUrl {@inheritdoc} yii\authclient\clients\Twitter
$apiBaseUrl {@inheritdoc} yii\authclient\clients\Twitter
$attributeParams array List of extra parameters, which should be used, while requesting user attributes from Twitter API. yii\authclient\clients\Twitter
$authUrl {@inheritdoc} yii\authclient\clients\Twitter
$authorizationHeaderMethods array|null List of the request methods, which require adding 'Authorization' header. yii\authclient\OAuth1
$autoRefreshAccessToken boolean Whether to automatically perform 'refresh access token' request on expired access token. yii\authclient\BaseOAuth
$consumerKey string OAuth consumer key. yii\authclient\OAuth1
$consumerSecret string OAuth consumer secret. yii\authclient\OAuth1
$requestTokenMethod {@inheritdoc} yii\authclient\clients\Twitter
$requestTokenUrl {@inheritdoc} yii\authclient\clients\Twitter
$scope string Auth request scope. yii\authclient\BaseOAuth
$version string Protocol version. yii\authclient\OAuth1

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\BaseObject
__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 returning response data. yii\authclient\BaseOAuth
applyAccessTokenToRequest() {@inheritdoc} yii\authclient\OAuth1
attachBehavior() Attaches a behavior to this component. yii\base\Component
attachBehaviors() Attaches a list of behaviors to the component. yii\base\Component
beforeApiRequestSend() Handles yii\httpclient\Request::EVENT_BEFORE_SEND event. yii\authclient\BaseOAuth
beforeRequestSend() Handles yii\httpclient\Request::EVENT_BEFORE_SEND event. yii\authclient\OAuth1
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\BaseObject
createApiRequest() {@inheritdoc} yii\authclient\OAuth1
createRequest() {@inheritdoc} yii\authclient\OAuth1
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
getHttpClient() Returns HTTP client. yii\authclient\BaseClient
getId() yii\authclient\ClientInterface
getName() yii\authclient\ClientInterface
getNormalizeUserAttributeMap() yii\authclient\BaseClient
getRequestOptions() yii\authclient\BaseClient
getReturnUrl() yii\authclient\BaseOAuth
getSignatureMethod() yii\authclient\BaseOAuth
getStateStorage() yii\authclient\BaseClient
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\BaseObject
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() Sets access token to be used. yii\authclient\BaseOAuth
setHttpClient() {@inheritdoc} yii\authclient\BaseOAuth
setId() yii\authclient\ClientInterface
setName() yii\authclient\ClientInterface
setNormalizeUserAttributeMap() yii\authclient\BaseClient
setRequestOptions() yii\authclient\BaseClient
setReturnUrl() yii\authclient\BaseOAuth
setSignatureMethod() Set signature method to be used. yii\authclient\BaseOAuth
setStateStorage() yii\authclient\BaseClient
setTitle() yii\authclient\ClientInterface
setUserAttributes() yii\authclient\BaseClient
setViewOptions() yii\authclient\BaseClient
signRequest() Sign given request with \yii\authclient\signatureMethod. yii\authclient\OAuth1
trigger() Triggers an event. yii\base\Component

Protected Methods

Hide inherited methods

MethodDescriptionDefined 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() {@inheritdoc} yii\authclient\clients\Twitter
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\OAuth1
defaultTitle() {@inheritdoc} yii\authclient\clients\Twitter
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() {@inheritdoc} yii\authclient\clients\Twitter
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

$accessTokenMethod public property
public $accessTokenMethod 'POST'
$accessTokenUrl public property
public $accessTokenUrl 'https://api.twitter.com/oauth/access_token'
$apiBaseUrl public property
public $apiBaseUrl 'https://api.twitter.com/1.1'
$attributeParams public property (available since version 2.0.6)

List of extra parameters, which should be used, while requesting user attributes from Twitter API. For example:

[
    'include_email' => 'true'
]

See also https://dev.twitter.com/rest/reference/get/account/verify_credentials.

public array $attributeParams = []
$authUrl public property
public $authUrl 'https://api.twitter.com/oauth/authenticate'
$requestTokenMethod public property
public $requestTokenMethod 'POST'
$requestTokenUrl public property
public $requestTokenUrl 'https://api.twitter.com/oauth/request_token'

Method Details

defaultName() protected method

{@inheritdoc}

protected void defaultName ( )
defaultTitle() protected method

{@inheritdoc}

protected void defaultTitle ( )
initUserAttributes() protected method

{@inheritdoc}

protected void initUserAttributes ( )