OAuth_Request_Authorize
› Kohana_OAuth_Request_Authorize
› OAuth_Request
› Kohana_OAuth_Request
Class Contents
Constants
- None
Properties
Class declared in MODPATH/oauth/classes/oauth/request/authorize.php on line 3.
Properties
- public
$send_header - public
$timeout
Methods
public execute( )
› Kohana_OAuth_Request_Authorize
Source Code
public function execute(array $options = NULL)
{
return Request::instance()->redirect($this->as_url());
}
public __construct( )
› Kohana_OAuth_Request
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) = OAuth::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);
}
if ($this->required('oauth_version') AND ! isset($this->params['oauth_version']))
{
// Set the version of this request
$this->params['oauth_version'] = OAuth::$version;
}
if ($this->required('oauth_timestamp') AND ! isset($this->params['oauth_timestamp']))
{
// Set the timestamp of this request
$this->params['oauth_timestamp'] = $this->timestamp();
}
if ($this->required('oauth_nonce') AND ! isset($this->params['oauth_nonce']))
{
// Set the unique nonce of this request
$this->params['oauth_nonce'] = $this->nonce();
}
}
public __get( )
› Kohana_OAuth_Request
Source Code
public function __get($key)
{
return $this->$key;
}
public as_header( )
› Kohana_OAuth_Request
Source Code
public function as_header()
{
$header = array();
foreach ($this->params as $name => $value)
{
if (strpos($name, 'oauth_') === 0)
{
// OAuth Spec 5.4.1
// "Parameter names and values are encoded per Parameter Encoding [RFC 3986]."
$header[] = OAuth::urlencode($name).'="'.OAuth::urlencode($value).'"';
}
}
return 'OAuth '.implode(', ', $header);
}
public as_query( )
› Kohana_OAuth_Request
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 ? OAuth::normalize_params($params) : $params;
}
public as_url( )
› Kohana_OAuth_Request
Source Code
public function as_url()
{
return $this->url.'?'.$this->as_query(TRUE);
}
public base_string( )
› Kohana_OAuth_Request
Source Code
public function base_string()
{
$url = $this->url;
// Get the request parameters
$params = array_diff_key($this->params, $this->upload);
// "oauth_signature" is never included in the base string!
unset($params['oauth_signature']);
// method & url & sorted-parameters
return implode('&', array(
$this->method,
OAuth::urlencode($url),
OAuth::urlencode(OAuth::normalize_params($params)),
));
}
public check( )
› Kohana_OAuth_Request
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( )
› Kohana_OAuth_Request
Source Code
public static function factory($type, $method, $url = NULL, array $params = NULL)
{
$class = 'OAuth_Request_'.$type;
return new $class($method, $url, $params);
}
public nonce( )
› Kohana_OAuth_Request
Source Code
public function nonce()
{
return Text::random('alnum', 40);
}
public param( )
› Kohana_OAuth_Request
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( )
› Kohana_OAuth_Request
Source Code
public function params(array $params, $duplicate = FALSE)
{
foreach ($params as $name => $value)
{
$this->param($name, $value, $duplicate);
}
return $this;
}
public required( )
› Kohana_OAuth_Request
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 sign( )
› Kohana_OAuth_Request
Source Code
public function sign(OAuth_Signature $signature, OAuth_Consumer $consumer, OAuth_Token $token = NULL)
{
// Create a new signature class from the method
$this->param('oauth_signature_method', $signature->name);
// Sign the request using the consumer and token
$this->param('oauth_signature', $signature->sign($this, $consumer, $token));
return $this;
}
public timestamp( )
› Kohana_OAuth_Request
Source Code
public function timestamp()
{
return time();
}
public upload( )
› Kohana_OAuth_Request
Source Code
public function upload($name, $value = NULL)
{
if ($value !== NULL)
{
// This is an upload parameter
$this->upload[$name] = TRUE;
// Get the mime type of the image
$mime = File::mime($value);
// Format the image path for CURL
$value = "@{$value};type={$mime}";
}
return $this->param($name, $value, FALSE);
}