/**
  * @param \OAuth\Common\Consumer\Credentials $credentials
  * @param \OAuth\Common\Http\Client\ClientInterface $httpClient
  * @param \OAuth\Common\Storage\TokenStorageInterface $storage
  * @param \OAuth\OAuth1\Signature\SignatureInterface $signature
  * @param UriInterface|null $baseApiUri
  */
 public function __construct(Credentials $credentials, ClientInterface $httpClient, TokenStorageInterface $storage, SignatureInterface $signature, UriInterface $baseApiUri = null)
 {
     parent::__construct($credentials, $httpClient, $storage);
     $this->signature = $signature;
     $this->baseApiUri = $baseApiUri;
     $this->signature->setHashingAlgorithm($this->getSignatureMethod());
 }
 /**
  * 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;
 }
Example #3
0
 /**
  * @param CredentialsInterface  $credentials
  * @param ClientInterface       $httpClient
  * @param TokenStorageInterface $storage
  * @param array                 $scopes
  * @param UriInterface|null     $baseApiUri
  * @param bool                  $stateParameterInAutUrl
  * @param string                $apiVersion
  *
  * @throws InvalidScopeException
  */
 public function __construct(CredentialsInterface $credentials, ClientInterface $httpClient, TokenStorageInterface $storage, $scopes = array(), UriInterface $baseApiUri = null, $stateParameterInAutUrl = false, $apiVersion = "")
 {
     parent::__construct($credentials, $httpClient, $storage);
     $this->scopes = $scopes;
     $this->baseApiUri = $baseApiUri;
     $this->apiVersion = $apiVersion;
 }
 /**
  * Implements OAuth authentication for Twitter
  *
  * @return null|bool          Returns a boolean on finished authentication.
  */
 public function oauthTwitter()
 {
     return $this->genericOAuthProvider(function () {
         // Get username, email and language
         $data = json_decode($this->service->request('account/verify_credentials.json?include_email=true'), true);
         $lang = isset($data['lang']) ? $data['lang'] : '';
         // Authenticate OAuth user against Grav system.
         return $this->authenticate($data['screen_name'], $data['id'], '', $lang);
     }, 'oauth1');
 }
 /**
  * @param Credentials           $credentials
  * @param ClientInterface       $httpClient
  * @param TokenStorageInterface $storage
  * @param array                 $scopes
  * @param UriInterface|null     $baseApiUri
  *
  * @throws InvalidScopeException
  */
 public function __construct(CredentialsInterface $credentials, ClientInterface $httpClient, TokenStorageInterface $storage, $scopes = array(), UriInterface $baseApiUri = null)
 {
     parent::__construct($credentials, $httpClient, $storage);
     foreach ($scopes as $scope) {
         if (!$this->isValidScope($scope)) {
             throw new InvalidScopeException('Scope ' . $scope . ' is not valid for service ' . get_class($this));
         }
     }
     $this->scopes = $scopes;
     $this->baseApiUri = $baseApiUri;
 }
 /**
  * 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;
 }
Example #7
0
 public function __construct(CredentialsInterface $credentials, Browser $httpTransporter, TokenStorageInterface $storage, $baseApiUrl)
 {
     parent::__construct($credentials, $httpTransporter, $storage, $baseApiUrl);
 }
Example #8
0
 /**
  * {@inheritdoc}
  */
 public function getAccessTokenEndpoint()
 {
     return $this->injectApiVersionToUri(parent::getAccessTokenEndpoint());
 }
Example #9
0
 /**
  * {@inheritDoc}
  */
 public function __construct(CredentialsInterface $credentials, Browser $httpTransporter, TokenStorageInterface $storage, SignatureInterface $signature, $baseApiUri = null)
 {
     parent::__construct($credentials, $httpTransporter, $storage, $baseApiUri);
     $this->signature = $signature;
     $this->signature->setHashingAlgorithm($this->getSignatureMethod());
 }
 /**
  * Login to an OAuth1 consumer.
  *
  * @param string                                $provider
  * @param \OAuth\Common\Service\AbstractService $service
  * 
  * @return Redirect
  */
 protected function oauth1Connect($provider, $service)
 {
     if ($oauth_token = Input::get('oauth_token')) {
         try {
             $token = $service->requestAccessToken($oauth_token, Input::get('oauth_verifier'), $service->getStorage()->retrieveAccessToken($provider)->getRequestTokenSecret());
         } catch (Exception $e) {
             return Redirect::to(Session::pull('mmanos.social.onerror', '/'))->with(Config::get('laravel-social::error_flash_var'), 'There was a problem connecting your account (4).');
         }
         return $this->processConnect($provider, $service, array('token' => $token->getAccessToken(), 'secret' => $token->getAccessTokenSecret()));
     }
     try {
         // Extra request needed for oauth1 to get a request token.
         $token = $service->requestRequestToken();
     } catch (Exception $e) {
         return Redirect::to(Session::pull('mmanos.social.onerror', '/'))->with(Config::get('laravel-social::error_flash_var'), 'There was a problem connecting your account (5).');
     }
     return Redirect::to((string) $service->getAuthorizationUri(array('oauth_token' => $token->getRequestToken())));
 }