/**
  * Request access token
  *
  * This is the second step of oAuth authentication
  *
  * This implementation tries to abstract away differences between oAuth1 and oAuth2,
  * but might need to be overwritten for specific services
  *
  * @return bool
  */
 public function checkToken()
 {
     global $INPUT;
     if (is_a($this->oAuth, 'OAuth\\OAuth2\\Service\\AbstractService')) {
         /* oAuth2 handling */
         if (!$INPUT->get->has('code')) {
             return false;
         }
         $state = $INPUT->get->str('state', null);
         try {
             $this->oAuth->requestAccessToken($INPUT->get->str('code'), $state);
         } catch (TokenResponseException $e) {
             msg($e->getMessage(), -1);
             return false;
         }
     } else {
         /* oAuth1 handling */
         if (!$INPUT->get->has('oauth_token')) {
             return false;
         }
         $token = $this->storage->retrieveAccessToken($this->getServiceName());
         // This was a callback request from BitBucket, get the token
         try {
             $this->oAuth->requestAccessToken($INPUT->get->str('oauth_token'), $INPUT->get->str('oauth_verifier'), $token->getRequestTokenSecret());
         } catch (TokenResponseException $e) {
             msg($e->getMessage(), -1);
             return false;
         }
     }
     return true;
 }
 /**
  * Request access token
  *
  * This is the second step of oAuth authentication
  *
  * This implementation tries to abstract away differences between oAuth1 and oAuth2,
  * but might need to be overwritten for specific services
  *
  * @return bool
  */
 public function checkToken()
 {
     global $INPUT;
     if (is_a($this->oAuth, 'OAuth\\OAuth2\\Service\\AbstractService')) {
         /* oAuth2 handling */
         if (!$INPUT->get->has('code')) {
             return false;
         }
         $state = $INPUT->get->str('state', null);
         try {
             $this->oAuth->requestAccessToken($INPUT->get->str('code'), $state);
         } catch (TokenResponseException $e) {
             msg($e->getMessage(), -1);
             return false;
         }
     } else {
         /* oAuth1 handling */
         if (!$INPUT->get->has('oauth_token')) {
             return false;
         }
         $token = $this->storage->retrieveAccessToken($this->getServiceName());
         // This was a callback request from BitBucket, get the token
         try {
             $this->oAuth->requestAccessToken($INPUT->get->str('oauth_token'), $INPUT->get->str('oauth_verifier'), $token->getRequestTokenSecret());
         } catch (TokenResponseException $e) {
             msg($e->getMessage(), -1);
             return false;
         }
     }
     $validDomains = $this->hlp->getValidDomains();
     if (count($validDomains) > 0) {
         $userData = $this->getUser();
         if (!$this->hlp->checkMail($userData['mail'])) {
             msg(sprintf($this->hlp->getLang("rejectedEMail"), join(', ', $validDomains)), -1);
             send_redirect(wl('', array('do' => 'login'), false, '&'));
         }
     }
     return true;
 }