/** * @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)); }
protected function oauthRequest($uri, $method = 'GET', $parameters = [], $headers = []) { $request = Request::fromConsumerAndToken($this->consumer, $this->consumerToken, $method, $uri, $parameters); $request->signRequest(new SignatureMethodHMACSHA1(), $this->consumer, $this->consumerToken); $parameters = array_merge($parameters, $request->parameters); $headers = array_replace($request->toHeader(), (array) $headers); $headers['Accept'] = 'application/json'; $headers['Content-Type'] = 'application/x-www-form-urlencoded'; $response = $this->service->getHttpClient()->request($request->getNormalizedHttpUrl(), $parameters, $method, $headers); return $response; }