PHP Class yii\authclient\BaseOAuth

See also: http://oauth.net/
Since: 2.0
Author: Paul Klimov ([email protected])
Inheritance: extends BaseClient, implements yii\authclient\ClientInterface
Mostrar archivo Open project: yiisoft/yii2-authclient Class Usage Examples

Public Properties

Property Type Description
$apiBaseUrl API base URL. This field will be used as [[\yii\httpclient\Client::baseUrl]] value of [[httpClient]]. Note: changing this property will take no effect after [[httpClient]] is instantiated.
$authUrl authorize URL.
$autoRefreshAccessToken whether to automatically perform 'refresh access token' request on expired access token.
$scope auth request scope.
$version protocol version.

Public Methods

Method Description
api ( string $apiSubUrl, string $method = 'GET', array | string $data = [], array $headers = [] ) : array Performs request to the OAuth API returning response data.
applyAccessTokenToRequest ( Request $request, OAuthToken $accessToken ) Applies access token to the HTTP request instance.
beforeApiRequestSend ( RequestEvent $event ) Handles [[Request::EVENT_BEFORE_SEND]] event.
createApiRequest ( ) : Request Creates an HTTP request for the API call.
getAccessToken ( ) : OAuthToken
getReturnUrl ( ) : string
getSignatureMethod ( ) : BaseMethod
refreshAccessToken ( OAuthToken $token ) : OAuthToken Gets new auth token to replace expired one.
setAccessToken ( array | OAuthToken $token ) Sets access token to be used.
setHttpClient ( $httpClient )
setReturnUrl ( string $returnUrl )
setSignatureMethod ( array | BaseMethod $signatureMethod ) Set signature method to be used.

Protected Methods

Method Description
composeUrl ( string $url, array $params = [] ) : string Composes URL from base URL and GET params.
createHttpClient ( $reference )
createSignatureMethod ( array $signatureMethodConfig ) : BaseMethod Creates signature method instance from its configuration.
createToken ( array $tokenConfig = [] ) : OAuthToken Creates token from its configuration.
defaultRequestOptions ( )
defaultReturnUrl ( ) : string Composes default [[returnUrl]] value.
restoreAccessToken ( ) : OAuthToken Restores access token.
saveAccessToken ( OAuthToken | null $token ) Saves token as persistent state.
sendRequest ( Request $request ) : array Sends the given HTTP request, returning response data.

Method Details

api() public method

You may use BaseOAuth::createApiRequest method instead, gaining more control over request execution.
See also: createApiRequest()
public api ( string $apiSubUrl, string $method = 'GET', array | string $data = [], array $headers = [] ) : array
$apiSubUrl string API sub URL, which will be append to [[apiBaseUrl]], or absolute API URL.
$method string request method.
$data array | string request data or content.
$headers array additional request headers.
return array API response data.

applyAccessTokenToRequest() abstract public method

Applies access token to the HTTP request instance.
Since: 2.1
abstract public applyAccessTokenToRequest ( Request $request, OAuthToken $accessToken )
$request yii\httpclient\Request HTTP request instance.
$accessToken OAuthToken access token instance.

beforeApiRequestSend() public method

Applies [[accessToken]] to the request.
Since: 2.1
public beforeApiRequestSend ( RequestEvent $event )
$event yii\httpclient\RequestEvent event instance.

composeUrl() protected method

Composes URL from base URL and GET params.
protected composeUrl ( string $url, array $params = [] ) : string
$url string base URL.
$params array GET params.
return string composed URL.

createApiRequest() public method

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.
See also: createRequest()
Since: 2.1
public createApiRequest ( ) : Request
return yii\httpclient\Request HTTP request instance.

createHttpClient() protected method

protected createHttpClient ( $reference )

createSignatureMethod() protected method

Creates signature method instance from its configuration.
protected createSignatureMethod ( array $signatureMethodConfig ) : BaseMethod
$signatureMethodConfig array signature method configuration.
return yii\authclient\signature\BaseMethod signature method instance.

createToken() protected method

Creates token from its configuration.
protected createToken ( array $tokenConfig = [] ) : OAuthToken
$tokenConfig array token configuration.
return OAuthToken token instance.

defaultRequestOptions() protected method

protected defaultRequestOptions ( )

defaultReturnUrl() protected method

Composes default [[returnUrl]] value.
protected defaultReturnUrl ( ) : string
return string return URL.

getAccessToken() public method

public getAccessToken ( ) : OAuthToken
return OAuthToken auth token instance.

getReturnUrl() public method

public getReturnUrl ( ) : string
return string return URL.

getSignatureMethod() public method

public getSignatureMethod ( ) : BaseMethod
return yii\authclient\signature\BaseMethod signature method instance.

refreshAccessToken() abstract public method

Gets new auth token to replace expired one.
abstract public refreshAccessToken ( OAuthToken $token ) : OAuthToken
$token OAuthToken expired auth token.
return OAuthToken new auth token.

restoreAccessToken() protected method

Restores access token.
protected restoreAccessToken ( ) : OAuthToken
return OAuthToken auth token.

saveAccessToken() protected method

Saves token as persistent state.
protected saveAccessToken ( OAuthToken | null $token )
$token OAuthToken | null auth token to be saved.

sendRequest() protected method

Sends the given HTTP request, returning response data.
Since: 2.1
protected sendRequest ( Request $request ) : array
$request yii\httpclient\Request HTTP request to be sent.
return array response data.

setAccessToken() public method

Sets access token to be used.
public setAccessToken ( array | OAuthToken $token )
$token array | OAuthToken access token or its configuration.

setHttpClient() public method

public setHttpClient ( $httpClient )

setReturnUrl() public method

public setReturnUrl ( string $returnUrl )
$returnUrl string return URL

setSignatureMethod() public method

Set signature method to be used.
public setSignatureMethod ( array | BaseMethod $signatureMethod )
$signatureMethod array | yii\authclient\signature\BaseMethod signature method instance or its array configuration.

Property Details

$apiBaseUrl public_oe property

API base URL. This field will be used as [[\yii\httpclient\Client::baseUrl]] value of [[httpClient]]. Note: changing this property will take no effect after [[httpClient]] is instantiated.
public $apiBaseUrl

$authUrl public_oe property

authorize URL.
public $authUrl

$autoRefreshAccessToken public_oe property

whether to automatically perform 'refresh access token' request on expired access token.
Since: 2.0.6
public $autoRefreshAccessToken

$scope public_oe property

auth request scope.
public $scope

$version public_oe property

protocol version.
public $version