protected function createResourceOwner(array $options, $name, $paths = null)
 {
     $this->buzzClient = $this->getMockBuilder('\\Buzz\\Client\\ClientInterface')->disableOriginalConstructor()->getMock();
     $httpUtils = $this->getMockBuilder('\\Symfony\\Component\\Security\\Http\\HttpUtils')->disableOriginalConstructor()->getMock();
     $resourceOwner = new GenericOAuth2ResourceOwner($this->buzzClient, $httpUtils, $options, $name);
     $resourceOwner->addPaths($paths ?: $this->getDefaultPaths());
     return $resourceOwner;
 }
 public function testCsrfTokenIsValidWhenDisabled()
 {
     if ($this->csrf) {
         $this->markTestSkipped('CSRF is enabled for this Resource Owner.');
     }
     $this->storage->expects($this->never())->method('fetch');
     $this->assertTrue($this->resourceOwner->isCsrfTokenValid('whatever you want'));
 }
 /**
  * {@inheritDoc}
  */
 protected function configureOptions(OptionsResolverInterface $resolver)
 {
     parent::configureOptions($resolver);
     $resolver->setDefaults(array('authorization_url' => 'https://accounts.google.com/o/oauth2/auth', 'access_token_url' => 'https://accounts.google.com/o/oauth2/token', 'revoke_token_url' => 'https://accounts.google.com/o/oauth2/revoke', 'infos_url' => 'https://www.googleapis.com/oauth2/v1/userinfo', 'scope' => 'https://www.googleapis.com/auth/userinfo.profile', 'access_type' => null, 'approval_prompt' => null, 'display' => null, 'hd' => null, 'login_hint' => null, 'prompt' => null, 'request_visible_actions' => null));
     if (method_exists($resolver, 'setDefined')) {
         $resolver->setAllowedValues('access_type', array('online', 'offline', null))->setAllowedValues('approval_prompt', array('force', 'auto', null))->setAllowedValues('display', array('page', 'popup', 'touch', 'wap', null))->setAllowedValues('login_hint', array('email address', 'sub', null))->setAllowedValues('prompt', array('consent', 'select_account', null));
     } else {
         $resolver->setAllowedValues(array('access_type' => array('online', 'offline', null), 'approval_prompt' => array('force', 'auto', null), 'display' => array('page', 'popup', 'touch', 'wap', null), 'login_hint' => array('email address', 'sub', null), 'prompt' => array('consent', 'select_account', null)));
     }
 }
 /**
  * {@inheritDoc}
  */
 protected function configureOptions(OptionsResolver $resolver)
 {
     parent::configureOptions($resolver);
     $resolver->setDefaults(array('authorization_url' => '{base_url}/oauth2/authorize', 'access_token_url' => '{base_url}/oauth2/token', 'revoke_token_url' => '{base_url}/oauth2/revoke', 'infos_url' => '{base_url}/user'));
     $resolver->setRequired(array('base_url'));
     $normalizer = function (Options $options, $value) {
         return str_replace('{base_url}', $options['base_url'], $value);
     };
     $resolver->setNormalizers(array('authorization_url' => $normalizer, 'access_token_url' => $normalizer, 'revoke_token_url' => $normalizer, 'infos_url' => $normalizer));
 }
 /**
  * {@inheritDoc}
  */
 protected function configureOptions(OptionsResolverInterface $resolver)
 {
     parent::configureOptions($resolver);
     $resolver->setRequired('base_url');
     $resolver->setDefaults(array('authorization_url' => '{base_url}/admin/oauth/authorize', 'access_token_url' => '{base_url}/admin/oauth/access_token', 'infos_url' => '{base_url}/admin/shop.json', 'use_bearer_authorization' => false));
     $baseUrlNormalizer = function (Options $options, $value) {
         return strtr($value, ['{base_url}' => $options['base_url']]);
     };
     $resolver->setNormalizers(['authorization_url' => $baseUrlNormalizer, 'access_token_url' => $baseUrlNormalizer, 'infos_url' => $baseUrlNormalizer]);
 }
 /**
  * {@inheritDoc}
  */
 protected function configureOptions(OptionsResolver $resolver)
 {
     parent::configureOptions($resolver);
     $resolver->setDefaults(array('authorization_url' => 'https://accounts.google.com/o/oauth2/auth', 'access_token_url' => 'https://accounts.google.com/o/oauth2/token', 'revoke_token_url' => 'https://accounts.google.com/o/oauth2/revoke', 'infos_url' => 'https://www.googleapis.com/youtube/v3/channels?part=id,snippet&mine=true', 'scope' => 'https://www.googleapis.com/auth/youtube.readonly', 'access_type' => null, 'approval_prompt' => null, 'display' => null, 'hd' => null, 'login_hint' => null, 'prompt' => null, 'request_visible_actions' => null));
     // Symfony <2.6 BC
     if (method_exists($resolver, 'setDefined')) {
         $resolver->setAllowedValues('access_type', array('online', 'offline', null))->setAllowedValues('approval_prompt', array('force', 'auto', null))->setAllowedValues('display', array('page', 'popup', 'touch', 'wap', null))->setAllowedValues('login_hint', array('email address', 'sub', null))->setAllowedValues('prompt', array(null, 'consent', 'select_account', null));
     } else {
         $resolver->setAllowedValues(array('access_type' => array('online', 'offline', null), 'approval_prompt' => array('force', 'auto', null), 'display' => array('page', 'popup', 'touch', 'wap', null), 'login_hint' => array('email address', 'sub', null), 'prompt' => array(null, 'consent', 'select_account', null)));
     }
 }
 /**
  * {@inheritDoc}
  */
 protected function configureOptions(OptionsResolverInterface $resolver)
 {
     parent::configureOptions($resolver);
     $resolver->setDefaults(array('authorization_url' => 'https://oauth.vk.com/authorize', 'access_token_url' => 'https://oauth.vk.com/access_token', 'infos_url' => 'https://api.vk.com/method/users.get', 'use_commas_in_scope' => true, 'fields' => 'nickname,photo_50', 'name_case' => null));
     $resolver->setNormalizers(array('fields' => function (Options $options, $value) {
         if (!$value) {
             return null;
         }
         return is_array($value) ? implode(',', $value) : $value;
     }));
 }
 /**
  * {@inheritDoc}
  */
 protected function configureOptions(OptionsResolverInterface $resolver)
 {
     parent::configureOptions($resolver);
     $resolver->setDefaults(array('authorization_url' => 'https://api.dailymotion.com/oauth/authorize', 'access_token_url' => 'https://api.dailymotion.com/oauth/token', 'infos_url' => 'https://api.dailymotion.com/me', 'display' => null));
     if (method_exists($resolver, 'setDefined')) {
         // @link http://www.dailymotion.com/doc/api/authentication.html#dialog-form-factors
         $resolver->setAllowedValues('display', array('page', 'popup', 'mobile', null));
     } else {
         $resolver->setAllowedValues(array('display' => array('page', 'popup', 'mobile', null)));
     }
 }
 /**
  * {@inheritDoc}
  */
 protected function configureOptions(OptionsResolverInterface $resolver)
 {
     parent::configureOptions($resolver);
     $resolver->setDefaults(array('authorization_url' => 'https://www.facebook.com/v2.0/dialog/oauth', 'access_token_url' => 'https://graph.facebook.com/v2.0/oauth/access_token', 'revoke_token_url' => 'https://graph.facebook.com/v2.0/me/permissions', 'infos_url' => 'https://graph.facebook.com/v2.0/me', 'use_commas_in_scope' => true, 'display' => null, 'auth_type' => null, 'appsecret_proof' => false));
     // Symfony <2.6 BC
     if (method_exists($resolver, 'setDefined')) {
         $resolver->setAllowedValues('display', array('page', 'popup', 'touch', null))->setAllowedValues('auth_type', array('rerequest', null))->setAllowedTypes('appsecret_proof', 'bool');
     } else {
         $resolver->setAllowedValues(array('display' => array('page', 'popup', 'touch', null), 'auth_type' => array('rerequest', null), 'appsecret_proof' => array(true, false)));
     }
 }
 /**
  * Override for Orcid
  *
  * {@inheritDoc}
  */
 public function getUserInformation(array $accessToken, array $extraParameters = array())
 {
     if (!array_key_exists('orcid', $accessToken)) {
         return parent::getUserInformation($accessToken, $extraParameters);
     }
     $orcidService = new OrcidService();
     $bio = $orcidService->getBio($accessToken["orcid"]);
     $response = $this->getUserResponse();
     $response->setResponse($bio);
     $response->setResourceOwner($this);
     $response->setOAuthToken(new OAuthToken($accessToken));
     return $response;
 }
 /**
  * {@inheritDoc}
  */
 protected function configureOptions(OptionsResolverInterface $resolver)
 {
     parent::configureOptions($resolver);
     $resolver->setDefaults(array('sandbox' => false, 'scope' => 'openid email', 'authorization_url' => 'https://www.paypal.com/webapps/auth/protocol/openidconnect/v1/authorize', 'access_token_url' => 'https://api.paypal.com/v1/identity/openidconnect/tokenservice', 'infos_url' => 'https://api.paypal.com/v1/identity/openidconnect/userinfo/?schema=openid'));
     $resolver->addAllowedTypes(array('sandbox' => 'bool'));
     $sandboxTransformation = function (Options $options, $value) {
         if (!$options['sandbox']) {
             return $value;
         }
         return preg_replace('~\\.paypal\\.~', '.sandbox.paypal.', $value, 1);
     };
     $resolver->setNormalizers(array('authorization_url' => $sandboxTransformation, 'access_token_url' => $sandboxTransformation, 'infos_url' => $sandboxTransformation));
 }
 /**
  * {@inheritDoc}
  */
 protected function configureOptions(OptionsResolver $resolver)
 {
     parent::configureOptions($resolver);
     $resolver->setDefaults(array('authorization_url' => '{base_url}/authorize', 'access_token_url' => '{base_url}/oauth/token', 'infos_url' => '{base_url}/userinfo'));
     $resolver->setRequired(array('base_url'));
     $normalizer = function (Options $options, $value) {
         return str_replace('{base_url}', $options['base_url'], $value);
     };
     // Symfony <2.6 BC
     if (method_exists($resolver, 'setNormalizer')) {
         $resolver->setNormalizer('authorization_url', $normalizer)->setNormalizer('access_token_url', $normalizer)->setNormalizer('infos_url', $normalizer);
     } else {
         $resolver->setNormalizers(array('authorization_url' => $normalizer, 'access_token_url' => $normalizer, 'infos_url' => $normalizer));
     }
 }
 /**
  * {@inheritDoc}
  */
 public function getUserInformation(array $accessToken, array $extraParameters = array())
 {
     $response = parent::getUserInformation($accessToken, $extraParameters);
     $responseData = $response->getResponse();
     // fetch the email addresses linked to the account
     if (empty($responseData['email'])) {
         $content = $this->httpRequest($this->normalizeUrl($this->options['emails_url']), null, array('Authorization: Bearer ' . $accessToken['access_token']));
         foreach ($this->getResponseContent($content)['values'] as $email) {
             // we only need the primary email address
             if (true === $email['is_primary']) {
                 $responseData['email'] = $email['email'];
             }
         }
         $response->setResponse($responseData);
     }
     return $response;
 }
 /**
  * {@inheritDoc}
  */
 protected function configureOptions(OptionsResolver $resolver)
 {
     parent::configureOptions($resolver);
     $resolver->setDefaults(array('authorization_url' => 'https://oauth.vk.com/authorize', 'access_token_url' => 'https://oauth.vk.com/access_token', 'infos_url' => 'https://api.vk.com/method/users.get', 'scope' => 'email', 'use_commas_in_scope' => true, 'fields' => 'nickname,photo_medium,screen_name,email', 'name_case' => null));
     $fieldsNormalizer = function (Options $options, $value) {
         if (!$value) {
             return null;
         }
         return is_array($value) ? implode(',', $value) : $value;
     };
     // Symfony <2.6 BC
     if (method_exists($resolver, 'setNormalizer')) {
         $resolver->setNormalizer('fields', $fieldsNormalizer);
     } else {
         $resolver->setNormalizers(array('fields' => $fieldsNormalizer));
     }
 }
 /**
  * {@inheritDoc}
  */
 protected function getResponseContent(HttpMessageInterface $rawResponse)
 {
     $response = parent::getResponseContent($rawResponse);
     // Foursquare use quite custom response structure in case of error
     if (isset($response['meta']['errorType'])) {
         // Prevent to mark deprecated calls as errors
         if (200 == $response['meta']['code']) {
             $response['error'] = $response['meta']['errorType'];
             // Try to add some details of error if available
             if (isset($response['meta']['errorMessage'])) {
                 $response['error'] .= ' ' . $response['meta']['errorMessage'];
             } elseif (isset($response['meta']['errorDetail'])) {
                 $response['error'] .= ' ' . $response['meta']['errorDetail'];
             }
         }
         unset($response['meta']);
     }
     return $response;
 }
Example #16
0
 /**
  * {@inheritDoc}
  */
 protected function configureOptions(OptionsResolverInterface $resolver)
 {
     parent::configureOptions($resolver);
     $resolver->setDefaults(array('sandbox' => false, 'authorization_url' => 'https://login.salesforce.com/services/oauth2/authorize', 'access_token_url' => 'https://login.salesforce.com/services/oauth2/token', 'infos_url' => null, 'format' => 'json'));
     $sandboxTransformation = function (Options $options, $value) {
         if (!$options['sandbox']) {
             return $value;
         }
         return preg_replace('~login\\.~', 'test.', $value, 1);
     };
     // Symfony <2.6 BC
     if (method_exists($resolver, 'setNormalizer')) {
         $resolver->setNormalizer('authorization_url', $sandboxTransformation)->setNormalizer('access_token_url', $sandboxTransformation);
         $resolver->addAllowedTypes('sandbox', 'bool');
     } else {
         $resolver->setNormalizers(array('authorization_url' => $sandboxTransformation, 'access_token_url' => $sandboxTransformation));
         $resolver->addAllowedTypes(array('sandbox' => 'bool'));
     }
 }
    /**
     * {@inheritDoc}
     */
    protected function configureOptions(OptionsResolverInterface $resolver)
    {
        parent::configureOptions($resolver);

        $resolver->setDefaults(array(
            'authorization_url'   => 'https://www.facebook.com/dialog/oauth',
            'access_token_url'    => 'https://graph.facebook.com/oauth/access_token',
            'revoke_token_url'    => 'https://graph.facebook.com/me/permissions',
            'infos_url'           => 'https://graph.facebook.com/me',

            'use_commas_in_scope' => true,

            'display'             => null,
        ));

        $resolver->setAllowedValues(array(
            // @link https://developers.facebook.com/docs/reference/dialogs/#display
            'display' => array('page', 'popup', 'touch'),
        ));
    }
 /**
  * {@inheritDoc}
  */
 protected function configureOptions(OptionsResolver $resolver)
 {
     parent::configureOptions($resolver);
     $resolver->setDefaults(array('authorization_url' => 'https://api.weibo.com/oauth2/authorize', 'access_token_url' => 'https://api.weibo.com/oauth2/access_token', 'infos_url' => 'https://api.weibo.com/2/users/show.json'));
 }
 /**
  * {@inheritDoc}
  */
 protected function configureOptions(OptionsResolver $resolver)
 {
     parent::configureOptions($resolver);
     $resolver->setDefaults(array('authorization_url' => 'https://public-api.wordpress.com/oauth2/authorize', 'access_token_url' => 'https://public-api.wordpress.com/oauth2/token', 'infos_url' => 'https://public-api.wordpress.com/rest/v1/me'));
 }
 /**
  * {@inheritDoc}
  */
 protected function configureOptions(OptionsResolverInterface $resolver)
 {
     parent::configureOptions($resolver);
     $resolver->setDefaults(array('authorization_url' => 'https://api.hubic.com/oauth/auth/', 'access_token_url' => 'https://api.hubic.com/oauth/token/', 'infos_url' => 'https://api.hubic.com/1.0/account'));
 }
 /**
  * {@inheritDoc}
  */
 protected function configureOptions(OptionsResolverInterface $resolver)
 {
     parent::configureOptions($resolver);
     $resolver->setDefaults(array('authorization_url' => 'https://www.box.com/api/oauth2/authorize', 'access_token_url' => 'https://www.box.com/api/oauth2/token', 'revoke_token_url' => 'https://www.box.com/api/oauth2/revoke', 'infos_url' => 'https://api.box.com/2.0/users/me'));
 }
 /**
  * {@inheritDoc}
  */
 protected function configureOptions(OptionsResolverInterface $resolver)
 {
     parent::configureOptions($resolver);
     $resolver->setDefaults(array('authorization_url' => 'http://www.odnoklassniki.ru/oauth/authorize', 'access_token_url' => 'http://api.odnoklassniki.ru/oauth/token.do', 'infos_url' => 'http://api.odnoklassniki.ru/fb.do?method=users.getCurrentUser', 'application_key' => null));
 }
 /**
  * {@inheritDoc}
  */
 protected function configureOptions(OptionsResolver $resolver)
 {
     parent::configureOptions($resolver);
     $resolver->setDefaults(array('authorization_url' => 'https://login.live.com/oauth20_authorize.srf', 'access_token_url' => 'https://login.live.com/oauth20_token.srf', 'infos_url' => 'https://apis.live.net/v5.0/me'));
 }
 /**
  * {@inheritDoc}
  */
 protected function configureOptions(OptionsResolver $resolver)
 {
     parent::configureOptions($resolver);
     $resolver->setDefaults(array('authorization_url' => 'https://stackexchange.com/oauth', 'access_token_url' => 'https://stackexchange.com/oauth/access_token', 'infos_url' => 'https://api.stackexchange.com/2.0/me', 'scope' => 'no_expiry'));
 }
 /**
  * {@inheritDoc}
  */
 protected function configureOptions(OptionsResolver $resolver)
 {
     parent::configureOptions($resolver);
     $resolver->setDefaults(array('authorization_url' => 'https://accounts.spotify.com/authorize', 'access_token_url' => 'https://accounts.spotify.com/api/token', 'infos_url' => 'https://api.spotify.com/v1/me'));
 }
 /**
  * {@inheritDoc}
  */
 protected function configureOptions(OptionsResolverInterface $resolver)
 {
     parent::configureOptions($resolver);
     $resolver->setDefaults(array('authorization_url' => 'https://foursquare.com/oauth2/authorize', 'access_token_url' => 'https://foursquare.com/oauth2/access_token', 'infos_url' => 'https://api.foursquare.com/v2/users/self', 'version' => '20121206'));
 }
 /**
  * {@inheritDoc}
  */
 protected function configureOptions(OptionsResolver $resolver)
 {
     parent::configureOptions($resolver);
     $resolver->setDefaults(array('authorization_url' => 'https://www.dropbox.com/1/oauth2/authorize', 'access_token_url' => 'https://api.dropbox.com/1/oauth2/token', 'infos_url' => 'https://api.dropbox.com/1/account/info'));
 }
 /**
  * {@inheritDoc}
  */
 protected function configureOptions(OptionsResolver $resolver)
 {
     parent::configureOptions($resolver);
     $resolver->setDefaults(array('authorization_url' => 'https://www.amazon.com/ap/oa', 'access_token_url' => 'https://api.amazon.com/auth/o2/token', 'infos_url' => 'https://api.amazon.com/user/profile', 'scope' => 'profile'));
 }
 /**
  * {@inheritDoc}
  */
 protected function configureOptions(OptionsResolverInterface $resolver)
 {
     parent::configureOptions($resolver);
     $resolver->setDefaults(array('authorization_url' => 'https://www.eventbrite.com/oauth/authorize', 'access_token_url' => 'https://www.eventbrite.com/oauth/token', 'infos_url' => 'https://www.eventbrite.com/json/user_get', 'use_bearer_authorization' => true));
 }
 /**
  * {@inheritDoc}
  */
 protected function configureOptions(OptionsResolverInterface $resolver)
 {
     parent::configureOptions($resolver);
     $resolver->setDefaults(array('authorization_url' => 'https://connect.mail.ru/oauth/authorize', 'access_token_url' => 'https://connect.mail.ru/oauth/token', 'infos_url' => 'http://www.appsmail.ru/platform/api'));
 }