public function DrupalOAuthClient::getRequestToken in OAuth 1.0 7.3
Same name and namespace in other branches
- 6.3 includes/DrupalOAuthClient.inc \DrupalOAuthClient::getRequestToken()
- 7.4 includes/DrupalOAuthClient.inc \DrupalOAuthClient::getRequestToken()
Gets a request token from the provider.
Parameters
string $endpoint: Optional. The endpoint path for the provider.
- If you provide the full URL (e.g. "http://example.com/oauth/request_token"), then it will be used.
- If you provide only the path (e.g. "oauth/request_token"), it will be converted into a full URL by prepending the provider_url.
- If you provide nothing it will default to '/oauth/request_token'.
array $options: An associative array of additional optional options, with the following keys:
- 'params' An associative array of parameters that should be included in the request.
- 'realm' A string to be used as the http authentication realm in the request.
- 'get' (default FALSE) Whether to use GET as the HTTP-method instead of POST.
- 'callback' A full URL of where the user should be sent after the request token has been authorized. Only used by versions higher than OAUTH_COMMON_VERSION_1.
Return value
DrupalOAuthToken The returned request token.
File
- includes/
DrupalOAuthClient.inc, line 95
Class
Code
public function getRequestToken($endpoint = NULL, $options = array()) {
if ($this->requestToken) {
return clone $this->requestToken;
}
$options += array(
'params' => array(),
'realm' => NULL,
'get' => FALSE,
'callback' => NULL,
);
if (empty($endpoint)) {
if (!empty($this->consumer->configuration['request_endpoint'])) {
$endpoint = $this->consumer->configuration['request_endpoint'];
}
else {
$endpoint = '/oauth/request_token';
}
}
if ($this->version > OAUTH_COMMON_VERSION_1) {
$options['params']['oauth_callback'] = $options['callback'] ? $options['callback'] : 'oob';
}
$response = $this
->get($endpoint, array(
'params' => $options['params'],
'realm' => $options['realm'],
'get' => $options['get'],
));
$params = array();
parse_str($response, $params);
if (empty($params['oauth_token']) || empty($params['oauth_token_secret'])) {
throw new Exception('No valid request token was returned');
}
if ($this->version > OAUTH_COMMON_VERSION_1 && empty($params['oauth_callback_confirmed'])) {
$this->version = OAUTH_COMMON_VERSION_1;
}
$this->requestToken = new DrupalOAuthToken($params['oauth_token'], $params['oauth_token_secret'], $this->consumer, array(
'type' => OAUTH_COMMON_TOKEN_TYPE_REQUEST,
'version' => $this->version,
));
return clone $this->requestToken;
}