Modules

OAuth2_Request_Authorize
extends OAuth2_Request

OAuth v2 Request Credentials

package
Gleez\OAuth
author
Sandeep Sangamreddi - Gleez
copyright
© 2011-2013 Gleez Technologies
license
http://gleezcms.org/license

Class declared in MODPATH/user/classes/oauth2/request/authorize.php on line 10.

Properties

public boolean $send_header

send Authorization header?

public integer $timeout

connection timeout

protected string $method

request method: GET, POST, etc

protected $name

protected array $params

request parameters

protected array $required

required parameters

protected array $upload

upload parameters

protected string $url

request URL

Methods

public execute( [ array $options = NULL ] ) (defined in OAuth2_Request_Authorize)

Execute the request and return a response.

Parameters

  • array $options = NULL - Additional cURL options

Tags

Return Values

  • string - Request response body

Source Code

public function execute(array $options = NULL)
{
	return Request::current()->redirect($this->as_url());
}

public __construct( string $method , string $url [, array $params = NULL ] ) (defined in OAuth2_Request)

Set the request URL, method, and parameters.

Parameters

  • string $method required - Request method
  • string $url required - Request URL
  • array $params = NULL - Request parameters

Tags

Source Code

public function __construct($method, $url, array $params = NULL)
{
	if ($method)
	{
		// Set the request method
		$this->method = strtoupper($method);
	}

	// Separate the URL and query string, which will be used as additional
	// default parameters
	list ($url, $default) = OAuth2::parse_url($url);

	// Set the request URL
	$this->url = $url;

	if ($default)
	{
		// Set the default parameters
		$this->params($default);
	}

	if ($params)
	{
		// Set the request parameters
		$this->params($params);
	}
}

public __get( string $key ) (defined in OAuth2_Request)

Return the value of any protected class variable.

// Get the request parameters
$params = $request->params;

// Get the request URL
$url = $request->url;

Parameters

  • string $key required - Variable name

Return Values

  • mixed

Source Code

public function __get($key)
{
	return $this->$key;
}

public as_query( [ boolean $include_oauth = NULL , boolean $as_string = bool TRUE ] ) (defined in OAuth2_Request)

Convert the request parameters into a query string, suitable for GET and POST requests.

$query = $request->as_query();

This method implements OAuth 1.0 Spec 5.2 (2,3).

Parameters

  • boolean $include_oauth = NULL - Include oauth parameters?
  • boolean $as_string = bool TRUE - Return a normalized string?

Return Values

  • string

Source Code

public function as_query($include_oauth = NULL, $as_string = TRUE)
{
	if ($include_oauth === NULL)
	{
		// If we are sending a header, OAuth parameters should not be
		// included in the query string.
		$include_oauth = ! $this->send_header;
	}

	if ($include_oauth)
	{
		$params = $this->params;
	}
	else
	{
		$params = array();
		foreach ($this->params as $name => $value)
		{
			if (strpos($name, 'oauth_') !== 0)
			{
				// This is not an OAuth parameter
				$params[$name] = $value;
			}
		}
	}

	return $as_string ? OAuth2::normalize_params($params) : $params;
}

public as_url( ) (defined in OAuth2_Request)

Return the entire request URL with the parameters as a GET string.

$url = $request->as_url();

Tags

Return Values

  • string

Source Code

public function as_url()
{
	return $this->url.'?'.$this->as_query(TRUE);
}

public check( ) (defined in OAuth2_Request)

Checks that all required request parameters have been set. Throws an exception if any parameters are missing.

try
{
    $request->check();
}
catch (OAuth_Exception $e)
{
    // Request has missing parameters
}

Tags

Return Values

  • TRUE

Source Code

public function check()
{
	foreach ($this->required as $param => $required)
	{
		if ($required AND ! isset($this->params[$param]))
		{
			throw new Kohana_OAuth_Exception('Request to :url requires missing parameter ":param"', array(
				':url'   => $this->url,
				':param' => $param,
			));
		}
	}

	return TRUE;
}

public static factory( string $type , string $method [, string $url = NULL , array $params = NULL ] ) (defined in OAuth2_Request)

Parameters

  • string $type required - $type
  • string $method required - $method
  • string $url = NULL - $url
  • array $params = NULL - $params

Tags

  • Static -

Return Values

  • OAuth2_Request

Source Code

public static function factory($type, $method, $url = NULL, array $params = NULL)
{
	$class = 'OAuth2_Request_'.$type;

	return new $class($method, $url, $params);
}

public format( ) (defined in OAuth2_Request)

Source Code

public function format($format = 'json')
{
	$this->format = 'json';

	return $this;
}

public param( string $name [, mixed $value = NULL , boolean $duplicate = bool FALSE ] ) (defined in OAuth2_Request)

Parameter getter and setter. Setting the value to NULL will remove it.

// Set the "oauth_consumer_key" to a new value
$request->param('oauth_consumer_key', $key);

// Get the "oauth_consumer_key" value
$key = $request->param('oauth_consumer_key');

Parameters

  • string $name required - Parameter name
  • mixed $value = NULL - Parameter value
  • boolean $duplicate = bool FALSE - Allow duplicates?

Tags

Return Values

  • mixed - When getting
  • $this - When setting

Source Code

public function param($name, $value = NULL, $duplicate = FALSE)
{
	if ($value === NULL)
	{
		// Get the parameter
		return Arr::get($this->params, $name);
	}

	if (isset($this->params[$name]) AND $duplicate)
	{
		if ( ! is_array($this->params[$name]))
		{
			// Convert the parameter into an array
			$this->params[$name] = array($this->params[$name]);
		}

		// Add the duplicate value
		$this->params[$name][] = $value;
	}
	else
	{
		// Set the parameter value
		$this->params[$name] = $value;
	}

	return $this;
}

public params( array $params [, boolean $duplicate = bool FALSE ] ) (defined in OAuth2_Request)

Set multiple parameters.

$request->params($params);

Parameters

  • array $params required - Parameters
  • boolean $duplicate = bool FALSE - Allow duplicates?

Tags

Return Values

  • $this

Source Code

public function params(array $params, $duplicate = FALSE)
{
	foreach ($params as $name => $value)
	{
		$this->param($name, $value, $duplicate);
	}

	return $this;
}

public required( string $param [, boolean $value = NULL ] ) (defined in OAuth2_Request)

Get and set required parameters.

$request->required($field, $value);

Parameters

  • string $param required - Parameter name
  • boolean $value = NULL - Field value

Return Values

  • boolean - When getting
  • $this - When setting

Source Code

public function required($param, $value = NULL)
{
	if ($value === NULL)
	{
		// Get the current status
		return ! empty($this->required[$param]);
	}

	// Change the requirement value
	$this->required[$param] = (boolean) $value;

	return $this;
}

public timestamp( ) (defined in OAuth2_Request)

Generates the UNIX timestamp for a request.

$time = $request->timestamp();

This method implements OAuth 1.0 Spec 8.

Return Values

  • integer

Source Code

public function timestamp()
{
	return time();
}
Documentation comments powered by Disqus