OAuthOAuth2ServiceLinkedin

Linkedin service.

Defined (1)

The class is defined in the following location(s).

/lib/PHPoAuthLib/src/OAuth/OAuth2/Service/Linkedin.php  
  1. class Linkedin extends AbstractService 
  2. /** 
  3. * Defined scopes 
  4. * @link http://developer.linkedin.com/documents/authentication#granting 
  5. */ 
  6. const SCOPE_R_BASICPROFILE = 'r_basicprofile'; 
  7. const SCOPE_R_FULLPROFILE = 'r_fullprofile'; 
  8. const SCOPE_R_EMAILADDRESS = 'r_emailaddress'; 
  9. const SCOPE_R_NETWORK = 'r_network'; 
  10. const SCOPE_R_CONTACTINFO = 'r_contactinfo'; 
  11. const SCOPE_RW_NUS = 'rw_nus'; 
  12. const SCOPE_RW_COMPANY_ADMIN = 'rw_company_admin'; 
  13. const SCOPE_RW_GROUPS = 'rw_groups'; 
  14. const SCOPE_W_MESSAGES = 'w_messages'; 
  15.  
  16. public function __construct( 
  17. CredentialsInterface $credentials,  
  18. ClientInterface $httpClient,  
  19. TokenStorageInterface $storage,  
  20. $scopes = array(),  
  21. UriInterface $baseApiUri = null 
  22. ) { 
  23. parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri, true); 
  24.  
  25. if (null === $baseApiUri) { 
  26. $this->baseApiUri = new Uri('https://api.linkedin.com/v1/'); 
  27.  
  28. /** 
  29. * {@inheritdoc} 
  30. */ 
  31. public function getAuthorizationEndpoint() 
  32. return new Uri('https://www.linkedin.com/uas/oauth2/authorization'); 
  33.  
  34. /** 
  35. * {@inheritdoc} 
  36. */ 
  37. public function getAccessTokenEndpoint() 
  38. return new Uri('https://www.linkedin.com/uas/oauth2/accessToken'); 
  39.  
  40. /** 
  41. * {@inheritdoc} 
  42. */ 
  43. protected function getAuthorizationMethod() 
  44. return static::AUTHORIZATION_METHOD_QUERY_STRING_V2; 
  45.  
  46. /** 
  47. * {@inheritdoc} 
  48. */ 
  49. protected function parseAccessTokenResponse($responseBody) 
  50. $data = json_decode($responseBody, true); 
  51.  
  52. if (null === $data || !is_array($data)) { 
  53. throw new TokenResponseException('Unable to parse response.'); 
  54. } elseif (isset($data['error'])) { 
  55. throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"'); 
  56.  
  57. $token = new StdOAuth2Token(); 
  58. $token->setAccessToken($data['access_token']); 
  59. $token->setLifeTime($data['expires_in']); 
  60.  
  61. if (isset($data['refresh_token'])) { 
  62. $token->setRefreshToken($data['refresh_token']); 
  63. unset($data['refresh_token']); 
  64.  
  65. unset($data['access_token']); 
  66. unset($data['expires_in']); 
  67.  
  68. $token->setExtraParams($data); 
  69.  
  70. return $token;