Modules
abstract Kohana_OAuth_Provider
OAuth Provider
Class declared in MODPATH/oauth/classes/kohana/oauth/provider.php on line 12.
Constants
- None
Properties
public
string$nameprovider name
protected
array$paramsadditional request parameters to be used for remote requests
Methods
public __construct( [ array $options = NULL ] ) (defined in Kohana_OAuth_Provider)
Overloads default class properties from the options.
Any of the provider options can be set here:
| Type | Option | Description | Default Value |
|---|---|---|---|
| mixed | signature | Signature method name or object | provider default |
Parameters
-
array$options = NULL - Provider options
Return Values
void
Source Code
public function __construct(array $options = NULL)
{
if (isset($options['signature']))
{
// Set the signature method name or object
$this->signature = $options['signature'];
}
if ( ! is_object($this->signature))
{
// Convert the signature name into an object
$this->signature = OAuth_Signature::factory($this->signature);
}
if ( ! $this->name)
{
// Attempt to guess the name from the class name
$this->name = strtolower(substr(get_class($this), strlen('OAuth_Provider_')));
}
}
public __get( string $key ) (defined in Kohana_OAuth_Provider)
Return the value of any protected class variable.
// Get the provider signature
$signature = $provider->signature;
Parameters
-
string$key required - Variable name
Return Values
mixed
Source Code
public function __get($key)
{
return $this->$key;
}
public access_token( OAuth_Consumer $consumer , OAuth_Token_Request $token [, array $params = NULL ] ) (defined in Kohana_OAuth_Provider)
Exchange the request token for an access token.
$token = $provider->access_token($consumer, $token);
Parameters
-
OAuth_Consumer$consumer required - Consumer -
OAuth_Token_Request$token required - Token -
array$params = NULL - Additional request parameters
Return Values
OAuth_Token_Access
Source Code
public function access_token(OAuth_Consumer $consumer, OAuth_Token_Request $token, array $params = NULL)
{
// Create a new GET request for a request token with the required parameters
$request = OAuth_Request::factory('access', 'GET', $this->url_access_token(), array(
'oauth_consumer_key' => $consumer->key,
'oauth_token' => $token->token,
'oauth_verifier' => $token->verifier,
));
if ($params)
{
// Load user parameters
$request->params($params);
}
// Sign the request using only the consumer, no token is available yet
$request->sign($this->signature, $consumer, $token);
// Create a response from the request
$response = $request->execute();
// Store this token somewhere useful
return OAuth_Token::factory('access', array(
'token' => $response->param('oauth_token'),
'secret' => $response->param('oauth_token_secret'),
));
}
public authorize_url( OAuth_Token_Request $token [, array $params = NULL ] ) (defined in Kohana_OAuth_Provider)
Get the authorization URL for the request token.
$this->request->redirect($provider->authorize_url($token));
Parameters
-
OAuth_Token_Request$token required - Token -
array$params = NULL - Additional request parameters
Return Values
string
Source Code
public function authorize_url(OAuth_Token_Request $token, array $params = NULL)
{
// Create a new GET request for a request token with the required parameters
$request = OAuth_Request::factory('authorize', 'GET', $this->url_authorize(), array(
'oauth_token' => $token->token,
));
if ($params)
{
// Load user parameters
$request->params($params);
}
return $request->as_url();
}
public static factory( string $name [, array $options = NULL ] ) (defined in Kohana_OAuth_Provider)
Create a new provider.
// Load the Twitter provider
$provider = OAuth_Provider::factory('twitter');
Parameters
-
string$name required - Provider name -
array$options = NULL - Provider options
Return Values
OAuth_Provider
Source Code
public static function factory($name, array $options = NULL)
{
$class = 'OAuth_Provider_'.$name;
return new $class($options);
}
public request_token( OAuth_Consumer $consumer [, array $params = NULL ] ) (defined in Kohana_OAuth_Provider)
Ask for a request token from the OAuth provider.
$token = $provider->request_token($consumer);
Parameters
-
OAuth_Consumer$consumer required - Consumer -
array$params = NULL - Additional request parameters
Tags
Return Values
OAuth_Token_Request
Source Code
public function request_token(OAuth_Consumer $consumer, array $params = NULL)
{
// Create a new GET request for a request token with the required parameters
$request = OAuth_Request::factory('token', 'GET', $this->url_request_token(), array(
'oauth_consumer_key' => $consumer->key,
'oauth_callback' => $consumer->callback,
));
if ($params)
{
// Load user parameters
$request->params($params);
}
// Sign the request using only the consumer, no token is available yet
$request->sign($this->signature, $consumer);
// Create a response from the request
$response = $request->execute();
// Store this token somewhere useful
return OAuth_Token::factory('request', array(
'token' => $response->param('oauth_token'),
'secret' => $response->param('oauth_token_secret'),
));
}
abstract public url_access_token( ) (defined in Kohana_OAuth_Provider)
Returns the access token endpoint for the provider.
$url = $provider->url_access_token();
Return Values
string
Source Code
abstract public function url_access_token();
abstract public url_authorize( ) (defined in Kohana_OAuth_Provider)
Returns the authorization URL for the provider.
$url = $provider->url_authorize();
Return Values
string
Source Code
abstract public function url_authorize();
abstract public url_request_token( ) (defined in Kohana_OAuth_Provider)
Returns the request token URL for the provider.
$url = $provider->url_request_token();
Return Values
string
Source Code
abstract public function url_request_token();