NOTE: For Version 3 of the AWS SDK for PHP, please see the V3 User Guide and V3 API Reference.

# Class OauthPlugin

OAuth signing plugin

  Guzzle\Plugin\Oauth\OauthPlugin implements Symfony\Component\EventDispatcher\EventSubscriberInterface

Namespace: Guzzle\Plugin\Oauth
Link: http://oauth.net/core/1.0/#rfc.section.9.1.1
Located at Guzzle/Plugin/Oauth/OauthPlugin.php

## Methods summary

- `public` `__construct ( array $config )`

  Create a new OAuth 1.0 plugin

- `public static` `getSubscribedEvents ( )`
- `public` `onRequestBeforeSend ( Guzzle\Common\Event $event )`

  Request before-send event handler

- `public` `getSignature ( Guzzle\Http\Message\RequestInterface $request, integer $timestamp, string $nonce )`

  Calculate signature for request

- `public` `getStringToSign ( Guzzle\Http\Message\RequestInterface $request, int $timestamp, string $nonce )`

  Calculate string to sign

- `protected` `getOauthParams ( mixed $timestamp, mixed $nonce )`

  Get the oauth parameters as named by the oauth spec

- `public` `getParamsToSign ( Guzzle\Http\Message\RequestInterface $request, integer $timestamp, string $nonce )`

  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` `shouldPostFieldsBeSigned ( mixed $request )`

  Decide whether the post fields should be added to the base string that Oauth signs. 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'

- `public` `generateNonce ( Guzzle\Http\Message\RequestInterface $request )`

  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` `getTimestamp ( Guzzle\Common\Event $event )`

  Gets timestamp from event or create new timestamp

- `protected` `prepareParameters ( array $data )`

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

## Methods detail

# `public`
`__construct( array $config )`

Create a new OAuth 1.0 plugin

#### Parameters

$config
  `array`
  $config 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

# `public static`
`getSubscribedEvents( )`
# `public array`
`onRequestBeforeSend( `Guzzle\Common\Event` $event )`

Request before-send event handler

#### Parameters

$event
  ``Guzzle\Common\Event``
  $event Event received

#### Returns

`array`

#### Throws

``InvalidArgumentException``
# `public string`
`getSignature( `Guzzle\Http\Message\RequestInterface` $request, integer $timestamp, string $nonce )`

Calculate signature for request

#### Parameters

$request
  ``Guzzle\Http\Message\RequestInterface``
  $request Request to generate a signature for
$timestamp
  `integer`
  $timestamp Timestamp to use for nonce
$nonce
  `string`
  $nonce

#### Returns

`string`
# `public string`
`getStringToSign( `Guzzle\Http\Message\RequestInterface` $request, integer $timestamp, string $nonce )`

Calculate string to sign

#### Parameters

$request
  ``Guzzle\Http\Message\RequestInterface``
  $request Request to generate a signature for
$timestamp
  `integer`
  $timestamp Timestamp to use for nonce
$nonce
  `string`
  $nonce

#### Returns

`string`
# `protected `Guzzle\Common\Collection``
`getOauthParams( mixed $timestamp, mixed $nonce )`

Get the oauth parameters as named by the oauth spec

#### Parameters

$timestamp
  `mixed`
  $timestamp
$nonce
  `mixed`
  $nonce

#### Returns

``Guzzle\Common\Collection``
# `public array`
`getParamsToSign( `Guzzle\Http\Message\RequestInterface` $request, integer $timestamp, string $nonce )`

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)

#### Parameters

$request
  ``Guzzle\Http\Message\RequestInterface``
  $request Request to generate a signature for
$timestamp
  `integer`
  $timestamp Timestamp to use for nonce
$nonce
  `string`
  $nonce

#### Returns

`array`
# `public boolean`
`shouldPostFieldsBeSigned( mixed $request )`

Decide whether the post fields should be added to the base string that Oauth signs. 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
  `mixed`
  $request

#### Returns

`boolean`
Whether the post fields should be signed or not
# `public string`
`generateNonce( `Guzzle\Http\Message\RequestInterface` $request )`

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.

#### Parameters

$request
  ``Guzzle\Http\Message\RequestInterface``
  $request Request to generate a nonce for

#### Returns

`string`
# `public integer`
`getTimestamp( `Guzzle\Common\Event` $event )`

Gets timestamp from event or create new timestamp

#### Parameters

$event
  ``Guzzle\Common\Event``
  $event Event containing contextual information

#### Returns

`integer`
# `protected array`
`prepareParameters( array $data )`

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

#### Parameters

$data
  `array`
  $data Data array

#### Returns

`array`

### Magic methods summary

## Constants summary

`string` | `REQUEST_METHOD_HEADER` | `'header'` | # Consumer request method constants. See http://oauth.net/core/1.0/#consumer_req_param
`string` | `REQUEST_METHOD_QUERY` | `'query'` | #

## Properties summary

`protected `Guzzle\Common\Collection`` | $config | # Configuration settings