/**
  * @param tubepress_spi_http_oauth2_Oauth2ProviderInterface $provider
  * @param $code
  *
  * @return tubepress_api_http_oauth_v2_TokenInterface
  */
 public function fetchWithCodeGrant(tubepress_spi_http_oauth2_Oauth2ProviderInterface $provider, $code)
 {
     $tokenUrl = $provider->getTokenEndpoint();
     $redirectUri = $this->_oauth2Environment->getRedirectionUrl($provider);
     $request = $this->_httpClient->createRequest('POST', $tokenUrl, array('body' => array('code' => $code, 'grant_type' => 'authorization_code', 'redirect_uri' => "{$redirectUri}")));
     $clientId = $this->_persistenceHelper->getClientId($provider);
     $clientSecret = $this->_persistenceHelper->getClientSecret($provider);
     $provider->onAccessTokenRequest($request, $clientId, $clientSecret);
     return $this->_fetchAndBuildToken($request, $provider);
 }
 /**
  * {@inheritdoc}
  */
 protected function getTemplateVariables()
 {
     $clientId = $this->_persistenceHelper->getClientId($this->_provider);
     $clientSecret = $this->_persistenceHelper->getClientSecret($this->_provider);
     $tokens = $this->getOptionPersistence()->fetch(tubepress_api_options_Names::OAUTH2_TOKENS);
     $decodedTokens = json_decode($tokens, true);
     $providerName = $this->_provider->getName();
     if (!isset($decodedTokens[$providerName]) || !is_array($decodedTokens[$providerName])) {
         $slugs = array();
     } else {
         $slugs = array_keys($decodedTokens[$providerName]);
     }
     return array('clientId' => $clientId, 'clientSecret' => $clientSecret, 'provider' => $this->_provider, 'oauth2StartUrl' => $this->_oauth2Environment->getAuthorizationInitiationUrl($this->_provider), 'slugs' => $slugs);
 }
 private function _validateCsrfToken()
 {
     $actualToken = (string) $this->getRequestParams()->getParamValue('csrf_token');
     $expectedToken = (string) $this->_oauth2Environment->getCsrfSecret();
     if ($actualToken !== $expectedToken) {
         $this->bail('Invalid csrf_token. Possible CSRF attack.');
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function getTemplateVariables()
 {
     $redirectUrl = $this->_oauth2Environment->getRedirectionUrl($this->_provider);
     $instructions = $this->_provider->getTranslatedClientRegistrationInstructions($this->_translator, $redirectUrl);
     return array('translatedInstructions' => $instructions);
 }