PHP Класс 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.
Автор: Neil Crookes ([email protected])
Наследование: extends HttpSocket
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$defaults array Default OAuth parameters. These get merged into the $request['auth'] param.

Открытые методы

Метод Описание
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.

Описание методов

assocToNumericNameValue() публичный Метод

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
Результат array

authorizationHeader() публичный Метод

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
Результат String

authorizationHeaderParamEncode() публичный Метод

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'
Результат string E.g. 'oauth_signature_method="HMAC-SHA1"'

parameterEncode() публичный Метод

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
Результат string

request() публичный Метод

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
Результат array

sortByNameThenByValue() публичный Метод

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'
Результат integer 1, 0 or -1 depending on whether a greater than b, less than or the same.

Описание свойств

$defaults публичное свойство

Default OAuth parameters. These get merged into the $request['auth'] param.
public array $defaults
Результат array