Esempio n. 1
0
 /**
  * {@inheritDoc}
  */
 public function requireScope($scope = null)
 {
     $temporaryCredentials = $this->oauthClient->getTemporaryCredentials();
     $authorizeUrl = $this->oauthClient->getAuthorizationUrl($temporaryCredentials);
     $this->session->set('provider/' . $this->getName() . '/temporary_credentials', $temporaryCredentials);
     return new RedirectResponse($authorizeUrl);
 }
Esempio n. 2
0
 /**
  * @param Application $app
  *
  * @return string token
  */
 public function handleAuth(Application $app)
 {
     $oauthToken = $app->request()->get('oauth_token');
     $oauthVerifier = $app->request()->get('oauth_verifier');
     $key = sprintf('bitbucket.oauthCredential.%s', session_id());
     $temporaryCredential = $this->redisClient->get($key);
     if (!empty($temporaryCredential)) {
         $temporaryCredential = unserialize($temporaryCredential);
     }
     if (empty($temporaryCredential)) {
         // If we don't have an authorization code then get one
         $temporaryCredential = $this->oauthProvider->getTemporaryCredentials();
         $this->redisClient->setex($key, 300, serialize($temporaryCredential));
         $app->redirect($this->oauthProvider->getAuthorizationUrl($temporaryCredential));
     } elseif (empty($oauthVerifier) || empty($oauthToken)) {
         // Check callback
         $this->redisClient->del($key);
         throw new \RuntimeException('Invalid state');
     }
     // clean session
     $this->redisClient->del($key);
     $tokenCredentials = $this->oauthProvider->getTokenCredentials($temporaryCredential, $oauthToken, $oauthVerifier);
     return $tokenCredentials->getIdentifier() . '@' . $tokenCredentials->getSecret();
 }