/** * Store a return url in the cache if provided. * * @param TemporaryCredentials $temp * * @return void */ protected function storeReturnUrl(TemporaryCredentials $temp) { if ($url = $this->request->get('return_url')) { $key = 'oauth_return_url_' . $temp->getIdentifier(); $this->cache->put($key, $url, ProviderContract::CACHE_TTL); } }
/** * Retrieves token credentials by passing in the temporary credentials, * the temporary credentials identifier as passed back by the server * and finally the verifier code. * * @param TemporaryCredentials $temporaryCredentials * @param string $temporaryIdentifier * @param string $verifier * * @return TokenCredentials */ public function getTokenCredentials(TemporaryCredentials $temporaryCredentials, $temporaryIdentifier, $verifier) { if ($temporaryIdentifier !== $temporaryCredentials->getIdentifier()) { throw new \InvalidArgumentException('Temporary identifier passed back by server does not match that of stored temporary credentials. Potential man-in-the-middle.'); } $uri = $this->urlTokenCredentials(); $bodyParameters = ['oauth_verifier' => $verifier]; $client = $this->createHttpClient(); $headers = $this->getHeaders($temporaryCredentials, 'POST', $uri, $bodyParameters); try { $response = $client->post($uri, $headers, $bodyParameters)->send(); } catch (BadResponseException $e) { return $this->handleTokenCredentialsBadResponse($e); } return ['tokenCredentials' => $this->createTokenCredentials($response->getBody()), 'credentialsResponseBody' => $response->getBody()]; }
/** * Retrieves token credentials by passing in the temporary credentials, * the temporary credentials identifier as passed back by the server * and finally the verifier code. * * @param TemporaryCredentials $temporaryCredentials * @param string $temporaryIdentifier * @param string $verifier * * @return TokenCredentials */ public function getTokenCredentials(TemporaryCredentials $temporaryCredentials, $temporaryIdentifier, $verifier) { if ($temporaryIdentifier !== $temporaryCredentials->getIdentifier()) { throw new \InvalidArgumentException('Temporary identifier passed back by server does not match that of stored temporary credentials. Potential man-in-the-middle.'); } // oauth_verifier must be at the end of the url, this doesn't seem to work otherwise $uri = $this->urlTokenCredentials() . '?oauth_verifier=' . $verifier; $bodyParameters = ['oauth_verifier' => $verifier, 'oauth_token' => $temporaryIdentifier]; $client = $this->createHttpClient(); $headers = $this->getHeaders($temporaryCredentials, 'POST', $uri, $bodyParameters); try { $response = $client->post($uri, ['headers' => $headers], ['body' => $bodyParameters]); } catch (BadResponseException $e) { return $this->handleTokenCredentialsBadResponse($e); } $responseString = (string) $response->getBody(); return ['tokenCredentials' => $this->createTokenCredentials($responseString), 'credentialsResponseBody' => $responseString]; }
/** * Retrieves token credentials by passing in the temporary credentials, * the temporary credentials identifier as passed back by the server * and finally the verifier code. * * @param TemporaryCredentials $temporaryCredentials * @param string $temporaryIdentifier * @param string $verifier * @return TokenCredentials */ public function getTokenCredentials(TemporaryCredentials $temporaryCredentials, $temporaryIdentifier, $verifier) { if ($temporaryIdentifier !== $temporaryCredentials->getIdentifier()) { throw new \InvalidArgumentException("Temporary identifier passed back by server does not match that of stored temporary credentials.\n Potential man-in-the-middle."); } $uri = $this->urlTokenCredentials(); $bodyParameters = array('oauth_verifier' => $verifier); $client = $this->createHttpClient(); $header = $this->protocolHeader('POST', $uri, $temporaryCredentials, $bodyParameters); $authorizationHeader = array('Authorization' => $header); $headers = $this->buildHttpClientHeaders($authorizationHeader); try { $response = $client->post($uri, $headers, $bodyParameters)->send(); } catch (BadResponseException $e) { return $this->handleTokenCredentialsBadResponse($e); } return $this->createTokenCredentials($response->getBody()); }
/** * Retrieves token credentials by passing in the temporary credentials, * the temporary credentials identifier as passed back by the server * and finally the verifier code. * * @since 0.2.3 * * @param TemporaryCredentials $temporaryCredentials * @param string $temporaryIdentifier * @param string $verifier * * @return TokenCredentials */ public function getTokenCredentials(TemporaryCredentials $temporaryCredentials, $temporaryIdentifier, $verifier) { if ($temporaryIdentifier !== $temporaryCredentials->getIdentifier()) { throw new \InvalidArgumentException('Temporary identifier passed back by server does not match that of stored temporary credentials. Potential man-in-the-middle.'); } $uri = $this->urlTokenCredentials(); $bodyParameters = array('oauth_verifier' => $verifier); $headers = $this->getHeaders($temporaryCredentials, 'POST', $uri, $bodyParameters); try { $this->get_response($uri, array('method' => 'POST', 'headers' => $headers, 'request_args' => $bodyParameters)); } catch (\Exception $e) { return $this->handleTokenCredentialsBadResponse($e); } return $this->createTokenCredentials($this->response->getBody()); }