Exemplo n.º 1
0
 /**
  * Process the return result from a user authorizing our app.
  */
 protected function handleCallback()
 {
     $next = false;
     if (isset($_SESSION[AuthManager::NEXTPAGE_SESSION_KEY])) {
         $next = $_SESSION[AuthManager::NEXTPAGE_SESSION_KEY];
         $next = filter_var($next, \FILTER_VALIDATE_URL, \FILTER_FLAG_PATH_REQUIRED);
     }
     if (!isset($_SESSION[self::REQEST_KEY])) {
         $this->flash('error', $this->msg('oauth-finish-nosession')->toString());
         $this->redirect($this->urlFor('login'));
     }
     list($key, $secret) = explode(':', $_SESSION[self::REQEST_KEY]);
     unset($_SESSION[self::REQEST_KEY]);
     $token = new Token($key, $secret);
     $this->form->requireString('oauth_verifier');
     $this->form->requireInArray('oauth_token', array($key));
     if ($this->form->validate($_GET)) {
         $verifyCode = $this->form->get('oauth_verifier');
         try {
             $accessToken = $this->oauth->complete($token, $verifyCode);
             $user = $this->manager->getUserData($accessToken);
             $this->authManager->login($user);
             $this->flash('info', $this->msg('oauth-finish-success')->toString());
         } catch (\Exception $e) {
             $this->flash('error', $this->msg('oauth-finish-fail')->toString());
             $this->log->error('Failed login attempt', array('exception' => $e));
         }
         $this->redirect($next ?: $this->urlFor('home'));
     } else {
         $this->flash('error', $this->msg('oauth-finish-fail')->toString());
     }
     $this->redirect($this->urlFor('login'));
 }
Exemplo n.º 2
0
 /**
  * Get a user by accessToken.
  *
  * @param Token $accessToken
  * @return UserData
  */
 public function getUserData($accessToken)
 {
     $ident = $this->oauth->identify($accessToken);
     return new OAuthUser($accessToken, $ident);
 }