/** * @param Request $request * @param Consumer $consumer * @param Token $token * @return string */ public function buildSignature(Request $request, Consumer $consumer, Token $token) { $signatureBase = $request->getSignatureBaseString(); $parts = array($consumer->getSecret(), null !== $token ? $token->getSecret() : ''); $parts = Util::urlencodeRFC3986($parts); $key = implode('&', $parts); return base64_encode(hash_hmac('sha1', $signatureBase, $key, true)); }
/** * @param Consumer $consumer * @param Token $token * @param string $method * @param string $url * @param array $parameters * @return Request */ public static function fromConsumerAndToken(Consumer $consumer, Token $token, $method, $url, array $parameters = array()) { $defaults = array('oauth_version' => self::$version, 'oauth_nonce' => self::generateNonce(), 'oauth_timestamp' => time(), 'oauth_consumer_key' => $consumer->getKey()); if ($token) { $defaults['oauth_token'] = $token->getKey(); } $parameters = array_merge($defaults, $parameters); return new self($method, $url, $parameters); }