コード例 #1
0
 /**
  * @param Request $request
  * @param User    $user
  *
  * @return array
  */
 public function handleOAuthCallback(Request $request, User $user = null)
 {
     $oauthVerifier = $request->get('oauth_verifier');
     $oauthToken = $request->get('oauth_token');
     $temporaryCredentials = $this->session->get('provider/' . $this->getName() . '/temporary_credentials');
     $tokenCredentials = $this->oauthClient->getTokenCredentials($temporaryCredentials, $oauthToken, $oauthVerifier);
     $userDetails = $this->oauthClient->getUserDetails($tokenCredentials);
     $accessToken = ['identifier' => $tokenCredentials->getIdentifier(), 'secret' => $tokenCredentials->getSecret(), 'username' => $userDetails->nickname];
     if (null !== $user) {
         $user->setProviderAccessToken($this->getName(), $accessToken);
     }
     return ['access_token' => $accessToken, 'scope' => null];
 }
コード例 #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();
 }