Class \Scrivo\Utilities\OAuthRequest

Class to send autorized reqeuests to a server using the OAuth 1.0 protocol.

Example (using bogus values):

$oAuth = new OAuth_1_0( "xvz1evFS4wEEPTGEFPHBog", //< consumer key "kAcSOqF21Fu85e7zjz7ZN2U4ZRhfV3WpwPAoE3Z7kBw", //< consumer secret "370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb", //< access token "LswwdoUaIvS8ltyTt5jkRh4J50vUPVVHtR2YPi5kE" //< access token secret );

// Send an authorized reqeuest to a Twitter service. echo $oAuth->sendRequest("get", "https://api.twitter.com/1.1/statuses/user_timeline.json?count=2");

Extends \Scrivo\Utilities\OAuth .
Defined in: Utilities/OAuthRequest.php.


Constructor summary

Attr. Name / Description
public

OAuthRequest($consumerKey, $consumerSecret, $token, $tokenSecret)

Construct an OAuth object: an object that is able to do authenticated requests.

Member summary

Attr. Type Name Description
private string $consumerKey The identifier portion of the client credentials (equivalent to a username).
private string $consumerSecret The client shared-secret, after being encoded
private string $token The token value used to associate the request with the resource owner.
private string $tokenSecret The token shared-secret, after being encoded
private string $version The OAuth version (currently we're only supporting 1.0);

Method summary

Attr. Type Name / Description
private

authorisationHeader($requestMethod, $baseUrl, $param)

Get the authorization request data for an OAuth reqeuest.

private string

encode($toEncode)

Return a percent encoded string.

private string

encodeKeyValuePairs($toEncode, $glue, $glue)

Percent encode an array of key/value pairs.

public object

getAuthorizationData($requestMethod, $url, $param)

Get the data for an OAuth 1.0 authorized request.

private string

nonce()

A nonce is a random string, uniquely generated by the client to allow the server to verify that a request has never been made before and helps prevent replay attacks when requests are made over a non-secure channel.

private string

normalizeParam($oauthParam, $param)

Normalize the collected parameters into a single string.

public string

sendRequest($requestMethod, $url, $param)

Get OAuth autorized data.

private string

sign($requestMethod, $baseUrl, $oauthParam, $requestParam)

Create the OAuth signature for a request.

private string

signatureBaseString($requestMethod, $baseUrl, $oauthParam, $oauthParam)

The signature base string is a consistent, reproducible concatenation of several of the HTTP request elements into a single string.

 


Constructor

public OAuthRequest(string $consumerKey, string $consumerSecret, string $token, string $tokenSecret)

Construct an OAuth object: an object that is able to do authenticated requests.

Inherited from \Scrivo\Utilities\OAuth

Parameters:

Type Name Def. Description
string $consumerKey

The identifier portion of the client credentials (equivalent to a username).

string $consumerSecret

The client shared-secret.

string $token

The token value used to associate the request with the resource owner.

string $tokenSecret

The token shared-secret.


Members


				
private string $consumerKey

The identifier portion of the client credentials (equivalent to a username).

The parameter name reflects a deprecated term (Consumer Key) used in previous revisions of the specification, and has been retained to maintain backward compatibility.

Inherited from \Scrivo\Utilities\OAuth

Inital value: null


				
private string $consumerSecret

The client shared-secret, after being encoded

Inherited from \Scrivo\Utilities\OAuth

Inital value: null


				
private string $token

The token value used to associate the request with the resource owner.

If the request is not associated with a resource owner (no token available), clients MAY omit the parameter.

Inherited from \Scrivo\Utilities\OAuth

Inital value: null


				
private string $tokenSecret

The token shared-secret, after being encoded

Inherited from \Scrivo\Utilities\OAuth

Inital value: null


				
private string $version

The OAuth version (currently we're only supporting 1.0);

Inherited from \Scrivo\Utilities\OAuth

Inital value: "1.0"


Methods

private authorisationHeader(string $requestMethod, string $baseUrl, string[] $param)

Get the authorization request data for an OAuth reqeuest.

Inherited from \Scrivo\Utilities\OAuth

Parameters:

Type Name Def. Description
string $requestMethod

The HTTP request method to use in the request.

string $baseUrl

The base URL of the Twitter API request (= the request URL including the protocol, host and path but excluding the parameters).

string[] $param

An array of request parameter key/value pairs.

private string encode(string $toEncode)

Return a percent encoded string.

Inherited from \Scrivo\Utilities\OAuth

Parameters:

Type Name Def. Description
string $toEncode

The data to percent encode.

Returns:

string Return a percent encoded string.

private string encodeKeyValuePairs(array $toEncode, string[] $glue, string[] $glue="")

Percent encode an array of key/value pairs.

The method allow for different glues to glue the encoded sets of key/value pairs together (apmerand and comma for example). It is also possible to supply a quotation mark for the values in the result string.

Inherited from \Scrivo\Utilities\OAuth

Parameters:

Type Name Def. Description
array $toEncode

An array with key/value pairs.

string[] $glue

The glue to bind the key/value pairs.

$quote $quote ""

Returns:

string Percent encode an array of key/value pairs.

public object getAuthorizationData(string $requestMethod, string $url, array $param=array())

Get the data for an OAuth 1.0 authorized request.

Inherited from \Scrivo\Utilities\OAuth

Parameters:

Type Name Def. Description
string $requestMethod

The HTTP request method to use in this request (GET or POST).

string $url

The URL for the request. Request parameters can be included in the URL. Note: this is an unescaped URL: ampersands should be "&" (not "&") and spaces should be " " (not "%20" or "+"), and this is not limited to ampersands and spaces.

array $param array()

Optional extra request parameters given as a set of name/value pairs. These parameters will get preceedence when name conflicts occur with parameters given in the $url parameter itself.

Returns:

object Get the data for an OAuth 1.0 authorized request.

private string nonce()

A nonce is a random string, uniquely generated by the client to allow the server to verify that a request has never been made before and helps prevent replay attacks when requests are made over a non-secure channel.

The nonce value MUST be unique across all requests with the same timestamp, client credentials, and token combinations.

Inherited from \Scrivo\Utilities\OAuth

Returns:

string A nonce is a random string, uniquely generated by the client to allow the server to verify that a request has never been made before and helps prevent replay attacks when requests are made over a non-secure channel.

private string normalizeParam(string[] $oauthParam, string[] $param)

Normalize the collected parameters into a single string.

Inherited from \Scrivo\Utilities\OAuth

Parameters:

Type Name Def. Description
string[] $oauthParam

An array of OAuth key/value pairs.

string[] $param

An array of request parameter key/value pairs.

Returns:

string Normalize the collected parameters into a single string.

public string sendRequest(string $requestMethod, string $url, array $param=array())

Get OAuth autorized data.

Parameters:

Type Name Def. Description
string $requestMethod

The HTTP request method to use in this request (GET or POST).

string $url

The URL of the service. Request parameters should be included in the URL. Note: this is an unescaped URL: ampersands should be "&" (not "&") and spaces should be " " (not "%20" or "+"), and this is not limited to ampersands and spaces.

array $param array()

Optional extra request parameters given as a set of name/value pairs. These parameters will get preceedence when name conflicts occur with parameters given in the $url parameter itself.

Returns:

string Get OAuth autorized data.

Throws:

Exception Type Description
\Scrivo\Utilities\Exception If there was a problem with retrieving data from the $url.
private string sign(string $requestMethod, string $baseUrl, string[] $oauthParam, string[] $requestParam)

Create the OAuth signature for a request.

Inherited from \Scrivo\Utilities\OAuth

Parameters:

Type Name Def. Description
string $requestMethod

The HTTP request method to use in this Twitter API request.

string $baseUrl

The base URL of the Twitter API request (= the request URL including the protocol, host and path but excluding the parameters).

string[] $oauthParam

An array of OAuth key/value pairs.

string[] $requestParam

An array of request parameter key/value pairs.

Returns:

string Create the OAuth signature for a request.

private string signatureBaseString(string $requestMethod, string $baseUrl, string[] $oauthParam, string[] $oauthParam)

The signature base string is a consistent, reproducible concatenation of several of the HTTP request elements into a single string.

The string is used as an input to the "HMAC-SHA1" and "RSA-SHA1" signature methods.

Inherited from \Scrivo\Utilities\OAuth

Parameters:

Type Name Def. Description
string $requestMethod

The HTTP request method to use in the request.

string $baseUrl

The base URL of the request (= the request URL including the protocol, host and path but excluding the parameters).

string[] $oauthParam

An array of OAuth key/value pairs.

$requestParam $requestParam

Returns:

string The signature base string is a consistent, reproducible concatenation of several of the HTTP request elements into a single string.


Documentation generated by phpDocumentor 2.0.0a12 and ScrivoDocumentor on August 29, 2013