function LingotekOAuthRequestSigner::sign in Lingotek Translation 7.6
Same name and namespace in other branches
- 7.7 lib/oauth-php/library/LingotekOAuthRequestSigner.php \LingotekOAuthRequestSigner::sign()
- 7.4 lib/oauth-php/library/LingotekOAuthRequestSigner.php \LingotekOAuthRequestSigner::sign()
- 7.5 lib/oauth-php/library/LingotekOAuthRequestSigner.php \LingotekOAuthRequestSigner::sign()
* Sign our message in the way the server understands. * Set the needed oauth_xxxx parameters. * *
Parameters
int usr_id (optional) user that wants to sign this request: * @param array secrets secrets used for signing, when empty then secrets will be fetched from the token registry * @param string name name of the token to be used for signing * @exception OAuthException2 when there is no oauth relation with the server * @exception OAuthException2 when we don't support the signing methods of the server
2 calls to LingotekOAuthRequestSigner::sign()
- LingotekOAuthRequester::doRequest in lib/
oauth-php/ library/ LingotekOAuthRequester.php - * Perform the request, returns the response code, headers and body. * *
- LingotekOAuthRequestSigner::getAuthorizationHeader in lib/
oauth-php/ library/ LingotekOAuthRequestSigner.php - * Builds the Authorization header for the request. * Adds all oauth_ and xoauth_ parameters to the Authorization header. * *
File
- lib/
oauth-php/ library/ LingotekOAuthRequestSigner.php, line 105
Class
Code
function sign($usr_id = 0, $secrets = null, $name = '', $token_type = null) {
$url = $this
->getRequestUrl();
if (empty($secrets)) {
// get the access tokens for the site (on an user by user basis)
$secrets = $this->store
->getSecretsForSignature($url, $usr_id, $name);
}
if (empty($secrets)) {
throw new OAuthException2('No OAuth relation with the server for at "' . $url . '"');
}
$signature_method = $this
->selectSignatureMethod($secrets['signature_methods']);
$token = isset($secrets['token']) ? $secrets['token'] : '';
$token_secret = isset($secrets['token_secret']) ? $secrets['token_secret'] : '';
if (!$token) {
$token = $this
->getParam('oauth_token');
}
$this
->setParam('oauth_signature_method', $signature_method);
$this
->setParam('oauth_signature', '');
$this
->setParam('oauth_nonce', !empty($secrets['nonce']) ? $secrets['nonce'] : uniqid(''));
$this
->setParam('oauth_timestamp', !empty($secrets['timestamp']) ? $secrets['timestamp'] : time());
if ($token_type != 'requestToken') {
$this
->setParam('oauth_token', $token);
}
$this
->setParam('oauth_consumer_key', $secrets['consumer_key']);
$this
->setParam('oauth_version', '1.0');
$body = $this
->getBody();
if (!is_null($body)) {
// We also need to sign the body, use the default signature method
$body_signature = $this
->calculateDataSignature($body, $secrets['consumer_secret'], $token_secret, $signature_method);
$this
->setParam('xoauth_body_signature', $body_signature, true);
}
$signature = $this
->calculateSignature($secrets['consumer_secret'], $token_secret, $token_type);
$this
->setParam('oauth_signature', $signature, true);
// $this->setParam('oauth_signature', urldecode($signature), true);
$this->signed = true;
$this->usr_id = $usr_id;
}