PHP Class OAuth2Handler, googleads-php-lib

Mostra file Open project: googleads/googleads-php-lib Class Usage Examples

Public Methods

Method Description
CanRefreshAccessToken ( array $credentials ) : boolean Determines if the access token can be refreshed.
FormatCredentialsForHeader ( array $credentials ) : string Formats OAuth2 credentials for use in an HTTP header.
FormatCredentialsForUrl ( array $credentials ) : string Formats OAuth2 credentials for use in a URL.
GetAccessToken ( array $credentials, string $code, string $redirectUri = null ) : array Gets the access token for an authorized request token.
GetAuthorizationUrl ( array $credentials, string $redirectUri = null, boolean $offline = null, array $params = null ) : string Gets the authorization URL to redirect to.
GetOrRefreshAccessToken ( array $credentials ) : array Get the valid access token or the token if needed and possible.
GetScopes ( ) : array Gets OAuth2 scopes.
IsAccessTokenExpiring ( array $credentials ) : boolean Tests if the access token is about to expire or has expired.
IsAccessTokenValid ( array $credentials ) : boolean Determines if the access token is still valid. If expiry information isn't available then this function will assume it is.
RefreshAccessToken ( array $credentials ) : array Refreshes the access token.
SetScopes ( $scopes ) Sets OAuth2 scopes.
ShouldRefreshAccessToken ( array $credentials ) : boolean Determines if the access token should be refreshed.
__construct ( array $scopes = null )

Protected Methods

Method Description
GetAccessEndpoint ( array $params = null ) : string Gets the access endpoint using the given server and parameters.
GetAuthorizeEndpoint ( array $params = null ) : string Gets the authorization endpoint using the given server and parameters.

Private Methods

Method Description
GetEndpoint ( string $endpoint, array $params = null ) : string Gets an endpoint using the given server and parameters.
GetExpiryTimestamp ( array $credentials ) : integer | boolean Get the expiry of a given credential, or false if none is found.

Method Details

CanRefreshAccessToken() public method

Determines if the access token can be refreshed.
public CanRefreshAccessToken ( array $credentials ) : boolean
$credentials array the credentials
return boolean true if the credentials can be refreshed

FormatCredentialsForHeader() public method

For example: Bearer token
public FormatCredentialsForHeader ( array $credentials ) : string
$credentials array the OAuth2 credentials
return string the credentials formatted for use in an HTTP header

FormatCredentialsForUrl() public method

For example: access_token=token.
public FormatCredentialsForUrl ( array $credentials ) : string
$credentials array the OAuth2 credentials
return string the credentials formatted for use in a URL

GetAccessEndpoint() protected method

Gets the access endpoint using the given server and parameters.
protected GetAccessEndpoint ( array $params = null ) : string
$params array the parameters to include in the endpoint
return string the access endpoint

GetAccessToken() abstract public method

Gets the access token for an authorized request token.
See also: https://developers.google.com/accounts/docs/OAuth2WebServer#handlingtheresponse
abstract public GetAccessToken ( array $credentials, string $code, string $redirectUri = null ) : array
$credentials array the credentials, including client_id and client_secret
$code string the authorization code returned in the response
$redirectUri string optional callback URL
return array the credentials passed in plus access_token, expires_in, timestamp and optionally refresh_token if offline mode was requested

GetAuthorizationUrl() public method

Gets the authorization URL to redirect to.
See also: https://developers.google.com/accounts/docs/OAuth2WebServer#formingtheurl
public GetAuthorizationUrl ( array $credentials, string $redirectUri = null, boolean $offline = null, array $params = null ) : string
$credentials array the credentials, including client_id
$redirectUri string optional callback URL
$offline boolean whether or not to request offline access (aka a refresh token), false by default
$params array optional array of additional parameters to include in the URL
return string an authorization URL to redirect the user to

GetAuthorizeEndpoint() protected method

Gets the authorization endpoint using the given server and parameters.
protected GetAuthorizeEndpoint ( array $params = null ) : string
$params array the parameters to include in the endpoint
return string the authorization endpoint

GetOrRefreshAccessToken() public method

Get the valid access token or the token if needed and possible.
public GetOrRefreshAccessToken ( array $credentials ) : array
$credentials array the credentials, including client_id and client_secret
return array the credentials passed in plus any refreshed credentials if they were refreshed

GetScopes() public method

Gets OAuth2 scopes.
public GetScopes ( ) : array
return array the list of OAuth2 scopes

IsAccessTokenExpiring() public method

Tests if the access token is about to expire or has expired.
public IsAccessTokenExpiring ( array $credentials ) : boolean
$credentials array the credentials, including access_token, timestamp and expires_in
return boolean true if the token has expired

IsAccessTokenValid() public method

Determines if the access token is still valid. If expiry information isn't available then this function will assume it is.
public IsAccessTokenValid ( array $credentials ) : boolean
$credentials array the credentials, including access_token, timestamp and expires_in
return boolean true if the access token is valid or if expiring information isn't available

RefreshAccessToken() abstract public method

Refreshes the access token.
See also: https://developers.google.com/accounts/docs/OAuth2WebServer#offline
abstract public RefreshAccessToken ( array $credentials ) : array
$credentials array the credentials, including the client_id, client_secret, refresh_token
return array the credentials

SetScopes() public method

Sets OAuth2 scopes.
public SetScopes ( $scopes )

ShouldRefreshAccessToken() public method

Determines if the access token should be refreshed.
public ShouldRefreshAccessToken ( array $credentials ) : boolean
$credentials array the credentials, including client_id and client_secret
return boolean true if the Access Token should be refreshed

__construct() public method

public __construct ( array $scopes = null )
$scopes array optional, Google API scopes this handler should use