protected function ServicesClientConnectionOAuthAuth::sign in Services Client 7.2
Same name and namespace in other branches
- 7 services_client_connection/modules/services_client_oauth/plugins/ServicesClientConnectionOAuthAuth.inc \ServicesClientConnectionOAuthAuth::sign()
Authenticate request
Parameters
ServicesClientConnectionHttpRequest $request:
1 call to ServicesClientConnectionOAuthAuth::sign()
- ServicesClientConnectionOAuthAuth::prepareRequest in services_client_connection/
modules/ services_client_oauth/ plugins/ ServicesClientConnectionOAuthAuth.inc - Implements prepareRequest().
File
- services_client_connection/
modules/ services_client_oauth/ plugins/ ServicesClientConnectionOAuthAuth.inc, line 123
Class
- ServicesClientConnectionOAuthAuth
- OAuth authentication support
Code
protected function sign(ServicesClientConnectionHttpRequest &$request) {
// Build params that should be signed
$params = $this
->getRequestParams($request);
// Get consumer and access token if configured
$consumer = new DrupalOAuthConsumer($this->config['consumer_key'], $this->config['consumer_secret']);
// Token doesn't have to be provided for 2legged auth
$token = NULL;
if (!empty($this->config['access_key']) && !empty($this->config['access_secret'])) {
$token = new DrupalOAuthToken($this->config['access_key'], $this->config['access_secret'], $consumer);
}
// Create request
$req = ServicesClientOAuthRequest::from_consumer_and_token($consumer, $token, $request->http_method, $request->url, $params);
// For special use cases we may need to force port to URL when calculating signature
if (isset($this->config['force_port']) && !empty($this->config['force_port'])) {
$req->force_port = $this->config['force_port'];
}
$signature_method = DrupalOAuthClient::signatureMethod();
$req
->sign_request($signature_method, $consumer, $token);
$header = explode(':', $req
->to_header());
$request->http_headers[$header[0]] = trim($header[1]);
// Store latest OAuthRequest
$this->request = $req;
}