class OAuth (View source)

The OAuth extension provides a simple interface to interact with data providers using the OAuth HTTP specification to protect private resources.

Properties

bool $debug
bool $sslChecks
array $debugInfo

Methods

__construct(string $consumer_key, string $consumer_secret, string $signature_method = OAUTH_SIG_METHOD_HMACSHA1, int $auth_type = OAUTH_AUTH_TYPE_AUTHORIZATION)

Create a new OAuth object

bool
disableDebug()

Turn off verbose debugging

void
disableRedirects()

Turn off redirects

bool
disableSSLChecks()

Turn off SSL checks

bool
enableDebug()

Turn on verbose debugging

bool
enableRedirects()

Turn on redirects

bool
enableSSLChecks()

Turn on SSL checks

void
setTimeout(int $timeout)

Set the timeout

mixed
fetch(string $protected_resource_url, array $extra_parameters = [], string $http_method = null, array $http_headers = [])

Fetch an OAuth-protected resource

array
getAccessToken(string $access_token_url, string $auth_session_handle = null, string $verifier_token = null)

Fetch an access token

array
getCAPath()

Get CA information

string
getLastResponse()

Get the last response

string|false
getLastResponseHeaders()

Get headers for last response

array
getLastResponseInfo()

Get HTTP information about the last response

string|false
getRequestHeader(string $http_method, string $url, mixed $extra_parameters = '')

Generate OAuth header string signature

array
getRequestToken(string $request_token_url, string $callback_url = null, string $http_method = 'GET')

Fetch a request token

bool
setAuthType(int $auth_type)

Set authorization type

mixed
setCAPath(string $ca_path = null, string $ca_info = null)

Set CA path and info

mixed
setNonce(string $nonce)

Set the nonce for subsequent requests

void
setRequestEngine(int $reqengine)

No description

mixed
setRSACertificate(string $cert)

Set the RSA certificate

mixed
setTimestamp(string $timestamp)

Set the timestamp

bool
setToken(string $token, string $token_secret)

Set the token and secret

bool
setVersion(string $version)

Set the OAuth version

Details

__construct(string $consumer_key, string $consumer_secret, string $signature_method = OAUTH_SIG_METHOD_HMACSHA1, int $auth_type = OAUTH_AUTH_TYPE_AUTHORIZATION)

Create a new OAuth object

Parameters

string $consumer_key

The consumer key provided by the service provider.

string $consumer_secret

The consumer secret provided by the service provider.

string $signature_method

This optional parameter defines which signature method to use, by default it is OAUTH_SIG_METHOD_HMACSHA1 (HMAC-SHA1).

int $auth_type

This optional parameter defines how to pass the OAuth parameters to a consumer, by default it is OAUTH_AUTH_TYPE_AUTHORIZATION (in the Authorization header).

Exceptions

OAuthException

bool disableDebug()

Turn off verbose debugging

Return Value

bool true

void disableRedirects()

Turn off redirects

Return Value

void

bool disableSSLChecks()

Turn off SSL checks

Return Value

bool true

bool enableDebug()

Turn on verbose debugging

Return Value

bool true

bool enableRedirects()

Turn on redirects

Return Value

bool

bool enableSSLChecks()

Turn on SSL checks

Return Value

bool true

void setTimeout(int $timeout)

Set the timeout

Parameters

int $timeout

Time in milliseconds

Return Value

void

mixed fetch(string $protected_resource_url, array $extra_parameters = [], string $http_method = null, array $http_headers = [])

Fetch an OAuth-protected resource

Parameters

string $protected_resource_url

URL to the OAuth protected resource.

array $extra_parameters

Extra parameters to send with the request for the resource.

string $http_method

One of the OAUTH_HTTPMETHOD* OAUTH constants, which includes GET, POST, PUT, HEAD, or DELETE. HEAD (OAUTH_HTTP_METHOD_HEAD) can be useful for discovering information prior to the request (if OAuth credentials are in the Authorization header).

array $http_headers

HTTP client headers (such as User-Agent, Accept, etc.)

Return Value

mixed

Returns true on success or false on failure.

Exceptions

OAuthException

array getAccessToken(string $access_token_url, string $auth_session_handle = null, string $verifier_token = null)

Fetch an access token

Parameters

string $access_token_url

URL to the access token API.

string $auth_session_handle

Authorization session handle, this parameter does not have any citation in the core OAuth 1.0 specification but may be implemented by large providers. See ScalableOAuth for more information.

string $verifier_token

For service providers which support 1.0a, a verifier_token must be passed while exchanging the request token for the access token. If the verifier_token is present in $_GET or $_POST it is passed automatically and the caller does not need to specify a verifier_token (usually if the access token is exchanged at the oauth_callback URL). See ScalableOAuth for more information.

Return Value

array

Returns an array containing the parsed OAuth response on success or false on failure.

Exceptions

OAuthException

array getCAPath()

Get CA information

Return Value

array

string getLastResponse()

Get the last response

Return Value

string

Returns a string containing the last response.

string|false getLastResponseHeaders()

Get headers for last response

Return Value

string|false

A string containing the last response's headers or false on failure

array getLastResponseInfo()

Get HTTP information about the last response

Return Value

array

Returns an array containing the response information for the last request. Constants from curl_getinfo may be used.

string|false getRequestHeader(string $http_method, string $url, mixed $extra_parameters = '')

Generate OAuth header string signature

Parameters

string $http_method

HTTP method for request.

string $url

URL for request.

mixed $extra_parameters

String or array of additional parameters.

Return Value

string|false

A string containing the generated request header or false on failure

array getRequestToken(string $request_token_url, string $callback_url = null, string $http_method = 'GET')

Fetch a request token

Parameters

string $request_token_url

URL to the request token API.

string $callback_url

OAuth callback URL. If callback_url is passed and is an empty value, it is set to "oob" to address the OAuth 2009.1 advisory.

string $http_method

HTTP method to use, e.g. GET or POST.

Return Value

array

Returns an array containing the parsed OAuth response on success or false on failure.

Exceptions

OAuthException

bool setAuthType(int $auth_type)

Set authorization type

Parameters

int $auth_type

auth_type can be one of the following flags (in order of decreasing preference as per OAuth 1.0 section 5.2): OAUTH_AUTH_TYPE_AUTHORIZATION Pass the OAuth parameters in the HTTP Authorization header. OAUTH_AUTH_TYPE_FORM Append the OAuth parameters to the HTTP POST request body. OAUTH_AUTH_TYPE_URI Append the OAuth parameters to the request URI. OAUTH_AUTH_TYPE_NONE None.

Return Value

bool

Returns true if a parameter is correctly set, otherwise false (e.g., if an invalid auth_type is passed in.)

mixed setCAPath(string $ca_path = null, string $ca_info = null)

Set CA path and info

Parameters

string $ca_path

The CA Path being set.

string $ca_info

The CA Info being set.

Return Value

mixed

mixed setNonce(string $nonce)

Set the nonce for subsequent requests

Parameters

string $nonce

The value for oauth_nonce.

Return Value

mixed

Returns true on success, or false if the nonce is considered invalid.

void setRequestEngine(int $reqengine)

No description

Parameters

int $reqengine

The desired request engine. Set to OAUTH_REQENGINE_STREAMS to use PHP Streams, or OAUTH_REQENGINE_CURL to use Curl.

Return Value

void

mixed setRSACertificate(string $cert)

Set the RSA certificate

Parameters

string $cert

The RSA certificate.

Return Value

mixed

mixed setTimestamp(string $timestamp)

Set the timestamp

Parameters

string $timestamp

The timestamp.

Return Value

mixed

bool setToken(string $token, string $token_secret)

Set the token and secret

Parameters

string $token

The OAuth token.

string $token_secret

The OAuth token secret.

Return Value

bool true

bool setVersion(string $version)

Set the OAuth version

Parameters

string $version

OAuth version, default value is always "1.0"

Return Value

bool

Returns true on success or false on failure.