public function ServicesClientDrupalOAuthClient::getRequestToken in Services Client 7.2
Same name and namespace in other branches
- 7 services_client_connection/modules/services_client_oauth/plugins/ServicesClientDrupalOAuthClient.inc \ServicesClientDrupalOAuthClient::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.
- 'force_port' A port number that is forced when creating normalized URL for calculating signature.
Return value
DrupalOAuthToken The returned request token.
File
- services_client_connection/
modules/ services_client_oauth/ plugins/ ServicesClientDrupalOAuthClient.inc, line 38 - Custom DrupalOAuthRequest implementation
Class
- ServicesClientDrupalOAuthClient
- @file Custom DrupalOAuthRequest implementation
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,
'force_port' => 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'],
'force_port' => $options['force_port'],
));
$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;
}