[ Index ]

PHP Cross Reference of phpBB-3.1.12-deutsch

title

Body

[close]

/vendor/lusitanian/oauth/src/OAuth/OAuth2/Service/ -> Linkedin.php (source)

   1  <?php
   2  
   3  namespace OAuth\OAuth2\Service;
   4  
   5  use OAuth\OAuth2\Token\StdOAuth2Token;
   6  use OAuth\Common\Http\Exception\TokenResponseException;
   7  use OAuth\Common\Http\Uri\Uri;
   8  use OAuth\Common\Consumer\CredentialsInterface;
   9  use OAuth\Common\Http\Client\ClientInterface;
  10  use OAuth\Common\Storage\TokenStorageInterface;
  11  use OAuth\Common\Http\Uri\UriInterface;
  12  
  13  /**
  14   * Linkedin service.
  15   *
  16   * @author Antoine Corcy <contact@sbin.dk>
  17   * @link http://developer.linkedin.com/documents/authentication
  18   */
  19  class Linkedin extends AbstractService
  20  {
  21      /**
  22       * Defined scopes
  23       * @link http://developer.linkedin.com/documents/authentication#granting
  24       */
  25      const SCOPE_R_BASICPROFILE      = 'r_basicprofile';
  26      const SCOPE_R_FULLPROFILE       = 'r_fullprofile';
  27      const SCOPE_R_EMAILADDRESS      = 'r_emailaddress';
  28      const SCOPE_R_NETWORK           = 'r_network';
  29      const SCOPE_R_CONTACTINFO       = 'r_contactinfo';
  30      const SCOPE_RW_NUS              = 'rw_nus';
  31      const SCOPE_RW_COMPANY_ADMIN    = 'rw_company_admin';
  32      const SCOPE_RW_GROUPS           = 'rw_groups';
  33      const SCOPE_W_MESSAGES          = 'w_messages';
  34  
  35      public function __construct(
  36          CredentialsInterface $credentials,
  37          ClientInterface $httpClient,
  38          TokenStorageInterface $storage,
  39          $scopes = array(),
  40          UriInterface $baseApiUri = null
  41      ) {
  42          parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri);
  43  
  44          if (null === $baseApiUri) {
  45              $this->baseApiUri = new Uri('https://api.linkedin.com/v1/');
  46          }
  47      }
  48  
  49      /**
  50       * {@inheritdoc}
  51       */
  52      public function getAuthorizationEndpoint()
  53      {
  54          return new Uri('https://www.linkedin.com/uas/oauth2/authorization');
  55      }
  56  
  57      /**
  58       * {@inheritdoc}
  59       */
  60      public function getAccessTokenEndpoint()
  61      {
  62          return new Uri('https://www.linkedin.com/uas/oauth2/accessToken');
  63      }
  64  
  65      /**
  66       * {@inheritdoc}
  67       */
  68      protected function getAuthorizationMethod()
  69      {
  70          return static::AUTHORIZATION_METHOD_QUERY_STRING_V2;
  71      }
  72  
  73      /**
  74       * {@inheritdoc}
  75       */
  76      protected function parseAccessTokenResponse($responseBody)
  77      {
  78          $data = json_decode($responseBody, true);
  79  
  80          if (null === $data || !is_array($data)) {
  81              throw new TokenResponseException('Unable to parse response.');
  82          } elseif (isset($data['error'])) {
  83              throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
  84          }
  85  
  86          $token = new StdOAuth2Token();
  87          $token->setAccessToken($data['access_token']);
  88          $token->setLifeTime($data['expires_in']);
  89  
  90          if (isset($data['refresh_token'])) {
  91              $token->setRefreshToken($data['refresh_token']);
  92              unset($data['refresh_token']);
  93          }
  94  
  95          unset($data['access_token']);
  96          unset($data['expires_in']);
  97  
  98          $token->setExtraParams($data);
  99  
 100          return $token;
 101      }
 102  }


Generated: Thu Jan 11 00:25:41 2018 Cross-referenced by PHPXref 0.7.1