PHP Class HttpSocketOauth, http_socket_oauth

The correct OAuth Authorization header is determined from the request params and then set in the $request['header']['Authorization'] param of the request array before passing it back to HttpSocket::request() to send the request and parse the response. So to trigger OAuth, add $request['auth']['method'] = 'OAuth' to your request. In addition, you'll need to add your consumer key in the $request['auth']['oauth_consumer_key'] and your consumer secret in the $request['auth']['oauth_consumer_secret'] param. These are given to you by the OAuth provider. And once you have them, $request['auth']['oauth_token'] and $request['auth']['oauth_token_secret'] params. Your OAuth provider may require you to send additional params too. Include them in the $request['auth'] array and they'll be passed on in the Authorization header and considered when signing the request.
Author: Neil Crookes ([email protected])
Inheritance: extends HttpSocket
Mostrar archivo Open project: neilcrookes/http_socket_oauth Class Usage Examples

Public Properties

Property Type Description
$defaults array Default OAuth parameters. These get merged into the $request['auth'] param.

Public Methods

Method Description
assocToNumericNameValue ( array $array ) : array Converts an associative array of name => value pairs to a numerically indexed array of array('name' => '', 'value' => '') elements.
authorizationHeader ( array $request ) : String Returns the OAuth Authorization Header string for a given request array.
authorizationHeaderParamEncode ( string $name, string $value ) : string Builds an Authorization header param string from the supplied name and value. See below for example:
parameterEncode ( string $param ) : string Encodes paramters as per the OAuth spec by utf 8 encoding the param (if it is not already utf 8 encoded) and then percent encoding it according to RFC3986
request ( array $request = [] ) : array Overrides HttpSocket::request() to handle cases where $request['auth']['method'] is 'OAuth'.
sortByNameThenByValue ( array $a, array $b ) : integer User defined function to lexically sort an array of array('name' => '', 'value' => '') elements by the value of the name key, and if they're the same, then by the value of the value key.

Method Details

assocToNumericNameValue() public method

Converts an associative array of name => value pairs to a numerically indexed array of array('name' => '', 'value' => '') elements.
public assocToNumericNameValue ( array $array ) : array
$array array Associative array
return array

authorizationHeader() public method

This method is called by request but can also be called directly, which is useful if you need to get the OAuth Authorization Header string, such as when integrating with a service that uses OAuth Echo (Authorization Delegation) e.g. Twitpic. In this case you send a normal unauthenticated request to the service e.g. Twitpic along with 2 extra headers: - X-Auth-Service-Provider - effectively, this is the realm that identity delegation should be sent to - in the case of Twitter, just set this to https://api.twitter.com/1/account/verify_credentials.json; - X-Verify-Credentials-Authorization - Consumer should create all the OAuth parameters necessary so it could call https://api.twitter.com/1/account/verify_credentials.json using OAuth in the HTTP header (e.g. it should look like OAuth oauth_consumer_key="...", oauth_token="...", oauth_signature_method="...", oauth_signature="...", oauth_timestamp="...", oauth_nonce="...", oauth_version="...".
public authorizationHeader ( array $request ) : String
$request array As required by HttpSocket::request(). NOTE ONLY THE ARRAY TYPE OF REQUEST IS SUPPORTED
return String

authorizationHeaderParamEncode() public method

Builds an Authorization header param string from the supplied name and value. See below for example:
public authorizationHeaderParamEncode ( string $name, string $value ) : string
$name string E.g. 'oauth_signature_method'
$value string E.g. 'HMAC-SHA1'
return string E.g. 'oauth_signature_method="HMAC-SHA1"'

parameterEncode() public method

Encodes paramters as per the OAuth spec by utf 8 encoding the param (if it is not already utf 8 encoded) and then percent encoding it according to RFC3986
public parameterEncode ( string $param ) : string
$param string
return string

request() public method

Overrides HttpSocket::request() to handle cases where $request['auth']['method'] is 'OAuth'.
public request ( array $request = [] ) : array
$request array As required by HttpSocket::request(). NOTE ONLY THE ARRAY TYPE OF REQUEST IS SUPPORTED
return array

sortByNameThenByValue() public method

User defined function to lexically sort an array of array('name' => '', 'value' => '') elements by the value of the name key, and if they're the same, then by the value of the value key.
public sortByNameThenByValue ( array $a, array $b ) : integer
$a array Array with key for 'name' and one for 'value'
$b array Array with key for 'name' and one for 'value'
return integer 1, 0 or -1 depending on whether a greater than b, less than or the same.

Property Details

$defaults public_oe property

Default OAuth parameters. These get merged into the $request['auth'] param.
public array $defaults
return array