/** * {@inheritdoc} * @param \Zeflasher\OAuth\Provider\OAuthRequest $request * @param string $consumer_secret * @param string $token_secret * @return string */ public function build_signature($request, $consumer_secret, $token_secret = '') { $base_string = $request->get_signature_base_string(); $request->base_string = $base_string; $key_parts = array( $consumer_secret, $token_secret ); $key_parts = \Zeflasher\OAuth\OAuthUtil::urlencode_rfc3986($key_parts); $key = implode('&', $key_parts); return base64_encode(hash_hmac('sha1', $base_string, $key, true)); }
/** * Builds the Authorization header * * @param string|null $realm * @return string * @throws \Zeflasher\OAuth\OAuthException */ public function to_header($realm=null) { $first = true; if($realm) { $out = 'Authorization: OAuth realm="' . \Zeflasher\OAuth\OAuthUtil::urlencode_rfc3986($realm) . '"'; $first = false; } else { $out = 'Authorization: OAuth'; } foreach ($this->_parameters as $k => $v) { if (substr($k, 0, 5) != "oauth") { continue; } if (is_array($v)) { throw new \Zeflasher\OAuth\OAuthException('Arrays not supported in headers'); } $out .= ($first) ? ' ' : ','; $out .= \Zeflasher\OAuth\OAuthUtil::urlencode_rfc3986($k) . '="' . \Zeflasher\OAuth\OAuthUtil::urlencode_rfc3986($v) . '"'; $first = false; } return $out; }
/** * Get a string with all the parameters alphabetically sorted and URL encoded. * @return string */ public function getSortedEncodedParametersAsString() { $params = getSortedParameters(); $paramsCount = count($params); $encodedString = ''; for ($i = 0; $i < $paramsCount; $i++) { $param = $params[$i]; if ($param->key != \Zeflasher\OAuth\OAuthConstants::OAUTH_CLIENT_SIGNATURE) { $encodedString .= \Zeflasher\OAuth\OAuthUtil::urlencode_rfc3986($param->key); $encodedString .= '='; $encodedString .= \Zeflasher\OAuth\OAuthUtil::urlencode_rfc3986($param->value); $encodedString .= '&'; } } // return them like a querystring return substr($encodedString, 0, strlen($encodedString)-1); }