Documentation

OauthPlugin
in package
implements EventSubscriberInterface

OAuth signing plugin

Tags
link
http://oauth.net/core/1.0/#rfc.section.9.1.1

Interfaces, Classes and Traits

EventSubscriberInterface
An EventSubscriber knows itself what events it is interested in.

Table of Contents

REQUEST_METHOD_HEADER  = 'header'
Consumer request method constants. See http://oauth.net/core/1.0/#consumer_req_param
REQUEST_METHOD_QUERY  = 'query'
$config  : Collection
__construct()  : mixed
Create a new OAuth 1.0 plugin
generateNonce()  : string
Returns a Nonce Based on the unique id and URL. This will allow for multiple requests in parallel with the same exact timestamp to use separate nonce's.
getParamsToSign()  : array<string|int, mixed>
Get all of the parameters required to sign a request including: * The oauth params * The request GET params * The params passed in the POST body (with a content-type of application/x-www-form-urlencoded)
getSignature()  : string
Calculate signature for request
getStringToSign()  : string
Calculate string to sign
getSubscribedEvents()  : array<string|int, mixed>
Returns an array of event names this subscriber wants to listen to.
getTimestamp()  : int
Gets timestamp from event or create new timestamp
onRequestBeforeSend()  : array<string|int, mixed>
Request before-send event handler
shouldPostFieldsBeSigned()  : bool
Decide whether the post fields should be added to the base string that Oauth signs.
getOauthParams()  : Collection
Get the oauth parameters as named by the oauth spec
prepareParameters()  : array<string|int, mixed>
Convert booleans to strings, removed unset parameters, and sorts the array
buildAuthorizationHeader()  : string
Builds the Authorization header for a request

Constants

REQUEST_METHOD_HEADER

Consumer request method constants. See http://oauth.net/core/1.0/#consumer_req_param

public mixed REQUEST_METHOD_HEADER = 'header'

REQUEST_METHOD_QUERY

public mixed REQUEST_METHOD_QUERY = 'query'

Properties

Methods

__construct()

Create a new OAuth 1.0 plugin

public __construct(array<string|int, mixed> $config) : mixed
Parameters
$config : array<string|int, mixed>

Configuration array containing these parameters:

  • string 'request_method' Consumer request method. Use the class constants.
  • string 'callback' OAuth callback
  • string 'consumer_key' Consumer key
  • string 'consumer_secret' Consumer secret
  • string 'token' Token
  • string 'token_secret' Token secret
  • string 'verifier' OAuth verifier.
  • string 'version' OAuth version. Defaults to 1.0
  • string 'signature_method' Custom signature method
  • bool 'disable_post_params' Set to true to prevent POST parameters from being signed
  • array|Closure 'signature_callback' Custom signature callback that accepts a string to sign and a signing key
Return values
mixed

generateNonce()

Returns a Nonce Based on the unique id and URL. This will allow for multiple requests in parallel with the same exact timestamp to use separate nonce's.

public generateNonce(RequestInterface $request) : string
Parameters
$request : RequestInterface

Request to generate a nonce for

Return values
string

getParamsToSign()

Get all of the parameters required to sign a request including: * The oauth params * The request GET params * The params passed in the POST body (with a content-type of application/x-www-form-urlencoded)

public getParamsToSign(RequestInterface $request, int $timestamp, string $nonce) : array<string|int, mixed>
Parameters
$request : RequestInterface

Request to generate a signature for

$timestamp : int

Timestamp to use for nonce

$nonce : string
Return values
array<string|int, mixed>

getSignature()

Calculate signature for request

public getSignature(RequestInterface $request, int $timestamp, string $nonce) : string
Parameters
$request : RequestInterface

Request to generate a signature for

$timestamp : int

Timestamp to use for nonce

$nonce : string
Return values
string

getStringToSign()

Calculate string to sign

public getStringToSign(RequestInterface $request, int $timestamp, string $nonce) : string
Parameters
$request : RequestInterface

Request to generate a signature for

$timestamp : int

Timestamp to use for nonce

$nonce : string
Return values
string

getSubscribedEvents()

Returns an array of event names this subscriber wants to listen to.

public static getSubscribedEvents() : array<string|int, mixed>

The array keys are event names and the value can be:

  • The method name to call (priority defaults to 0)
  • An array composed of the method name to call and the priority
  • An array of arrays composed of the method names to call and respective priorities, or 0 if unset

For instance:

  • ['eventName' => 'methodName']
  • ['eventName' => ['methodName', $priority]]
  • ['eventName' => [['methodName1', $priority], ['methodName2']]]

The code must not depend on runtime state as it will only be called at compile time. All logic depending on runtime state must be put into the individual methods handling the events.

Return values
array<string|int, mixed>

The event names to listen to

getTimestamp()

Gets timestamp from event or create new timestamp

public getTimestamp(Event $event) : int
Parameters
$event : Event

Event containing contextual information

Return values
int

onRequestBeforeSend()

Request before-send event handler

public onRequestBeforeSend(Event $event) : array<string|int, mixed>
Parameters
$event : Event

Event received

Tags
throws
InvalidArgumentException
Return values
array<string|int, mixed>

shouldPostFieldsBeSigned()

Decide whether the post fields should be added to the base string that Oauth signs.

public shouldPostFieldsBeSigned( $request) : bool

This implementation is correct. Non-conformant APIs may require that this method be overwritten e.g. the Flickr API incorrectly adds the post fields when the Content-Type is 'application/x-www-form-urlencoded'

Parameters
$request :
Return values
bool

Whether the post fields should be signed or not

getOauthParams()

Get the oauth parameters as named by the oauth spec

protected getOauthParams( $timestamp,  $nonce) : Collection
Parameters
$timestamp :
$nonce :
Return values
Collection

prepareParameters()

Convert booleans to strings, removed unset parameters, and sorts the array

protected prepareParameters(array<string|int, mixed> $data) : array<string|int, mixed>
Parameters
$data : array<string|int, mixed>

Data array

Return values
array<string|int, mixed>

buildAuthorizationHeader()

Builds the Authorization header for a request

private buildAuthorizationHeader(array<string|int, mixed> $authorizationParams) : string
Parameters
$authorizationParams : array<string|int, mixed>

Associative array of authorization parameters

Return values
string

Search results