OAuth v2 Request Credentials
Class declared in MODPATH/user/classes/oauth2/request/authorize.php on line 10.
boolean $send_headersend Authorization header?
integer $timeoutconnection timeout
string $methodrequest method: GET, POST, etc
$namearray $paramsrequest parameters
array $requiredrequired parameters
array $uploadupload parameters
string $urlrequest URL
Execute the request and return a response.
array
$options
= NULL - Additional cURL optionsstring - Request response bodypublic function execute(array $options = NULL)
{
return Request::current()->redirect($this->as_url());
}
Set the request URL, method, and parameters.
string
$method
required - Request methodstring
$url
required - Request URLarray
$params
= NULL - Request parameterspublic 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);
}
}
Return the value of any protected class variable.
// Get the request parameters
$params = $request->params;
// Get the request URL
$url = $request->url;
string
$key
required - Variable namemixedpublic function __get($key)
{
return $this->$key;
}
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).
boolean
$include_oauth
= NULL - Include oauth parameters?boolean
$as_string
= bool TRUE - Return a normalized string?stringpublic 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;
}
Return the entire request URL with the parameters as a GET string.
$url = $request->as_url();
stringpublic function as_url()
{
return $this->url.'?'.$this->as_query(TRUE);
}
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
}
TRUEpublic 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;
}
string
$type
required - $typestring
$method
required - $methodstring
$url
= NULL - $urlarray
$params
= NULL - $paramsOAuth2_Requestpublic static function factory($type, $method, $url = NULL, array $params = NULL)
{
$class = 'OAuth2_Request_'.$type;
return new $class($method, $url, $params);
}
public function format($format = 'json')
{
$this->format = 'json';
return $this;
}
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');
string
$name
required - Parameter namemixed
$value
= NULL - Parameter valueboolean
$duplicate
= bool FALSE - Allow duplicates?mixed - When getting$this - When settingpublic 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;
}
Set multiple parameters.
$request->params($params);
array
$params
required - Parametersboolean
$duplicate
= bool FALSE - Allow duplicates?$thispublic function params(array $params, $duplicate = FALSE)
{
foreach ($params as $name => $value)
{
$this->param($name, $value, $duplicate);
}
return $this;
}
Get and set required parameters.
$request->required($field, $value);
string
$param
required - Parameter nameboolean
$value
= NULL - Field valueboolean - When getting$this - When settingpublic 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;
}
Generates the UNIX timestamp for a request.
$time = $request->timestamp();
This method implements OAuth 1.0 Spec 8.
integerpublic function timestamp()
{
return time();
}