OAuthOAuth2ServiceMicrosoft

The Gravity Forms Salesforce Add-On OAuth OAuth2 Service Microsoft class.

Defined (1)

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

/lib/PHPoAuthLib/src/OAuth/OAuth2/Service/Microsoft.php  
  1. class Microsoft extends AbstractService 
  2. const SCOPE_BASIC = 'wl.basic'; 
  3. const SCOPE_OFFLINE = 'wl.offline_access'; 
  4. const SCOPE_SIGNIN = 'wl.signin'; 
  5. const SCOPE_BIRTHDAY = 'wl.birthday'; 
  6. const SCOPE_CALENDARS = 'wl.calendars'; 
  7. const SCOPE_CALENDARS_UPDATE = 'wl.calendars_update'; 
  8. const SCOPE_CONTACTS_BIRTHDAY = 'wl.contacts_birthday'; 
  9. const SCOPE_CONTACTS_CREATE = 'wl.contacts_create'; 
  10. const SCOPE_CONTACTS_CALENDARS = 'wl.contacts_calendars'; 
  11. const SCOPE_CONTACTS_PHOTOS = 'wl.contacts_photos'; 
  12. const SCOPE_CONTACTS_SKYDRIVE = 'wl.contacts_skydrive'; 
  13. const SCOPE_EMAILS = 'wl.emails'; 
  14. const SCOPE_EVENTS_CREATE = 'wl.events_create'; 
  15. const SCOPE_MESSENGER = 'wl.messenger'; 
  16. const SCOPE_PHONE_NUMBERS = 'wl.phone_numbers'; 
  17. const SCOPE_PHOTOS = 'wl.photos'; 
  18. const SCOPE_POSTAL_ADDRESSES = 'wl.postal_addresses'; 
  19. const SCOPE_SHARE = 'wl.share'; 
  20. const SCOPE_SKYDRIVE = 'wl.skydrive'; 
  21. const SCOPE_SKYDRIVE_UPDATE = 'wl.skydrive_update'; 
  22. const SCOPE_WORK_PROFILE = 'wl.work_profile'; 
  23. const SCOPE_APPLICATIONS = 'wl.applications'; 
  24. const SCOPE_APPLICATIONS_CREATE = 'wl.applications_create'; 
  25.  
  26. /** 
  27. * MS uses some magical not officialy supported scope to get even moar info like full emailaddresses. 
  28. * They agree that giving 3rd party apps access to 3rd party emailaddresses is a pretty lame thing to do so in all 
  29. * their wisdom they added this scope because fuck you that's why. 
  30. * https://github.com/Lusitanian/PHPoAuthLib/issues/214 
  31. * http://social.msdn.microsoft.com/Forums/live/en-US/c6dcb9ab-aed4-400a-99fb-5650c393a95d/how-retrieve-users- 
  32. * contacts-email-address?forum=messengerconnect 
  33. * Considering this scope is not officially supported: use with care 
  34. */ 
  35. const SCOPE_CONTACTS_EMAILS = 'wl.contacts_emails'; 
  36.  
  37. public function __construct( 
  38. CredentialsInterface $credentials,  
  39. ClientInterface $httpClient,  
  40. TokenStorageInterface $storage,  
  41. $scopes = array(),  
  42. UriInterface $baseApiUri = null 
  43. ) { 
  44. parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri); 
  45.  
  46. if (null === $baseApiUri) { 
  47. $this->baseApiUri = new Uri('https://apis.live.net/v5.0/'); 
  48.  
  49. /** 
  50. * {@inheritdoc} 
  51. */ 
  52. public function getAuthorizationEndpoint() 
  53. return new Uri('https://login.live.com/oauth20_authorize.srf'); 
  54.  
  55. /** 
  56. * {@inheritdoc} 
  57. */ 
  58. public function getAccessTokenEndpoint() 
  59. return new Uri('https://login.live.com/oauth20_token.srf'); 
  60.  
  61. /** 
  62. * {@inheritdoc} 
  63. */ 
  64. public function getAuthorizationMethod() 
  65. return static::AUTHORIZATION_METHOD_QUERY_STRING; 
  66.  
  67. /** 
  68. * {@inheritdoc} 
  69. */ 
  70. protected function parseAccessTokenResponse($responseBody) 
  71. $data = json_decode($responseBody, true); 
  72.  
  73. if (null === $data || !is_array($data)) { 
  74. throw new TokenResponseException('Unable to parse response.'); 
  75. } elseif (isset($data['error'])) { 
  76. throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"'); 
  77.  
  78. $token = new StdOAuth2Token(); 
  79. $token->setAccessToken($data['access_token']); 
  80. $token->setLifetime($data['expires_in']); 
  81.  
  82. if (isset($data['refresh_token'])) { 
  83. $token->setRefreshToken($data['refresh_token']); 
  84. unset($data['refresh_token']); 
  85.  
  86. unset($data['access_token']); 
  87. unset($data['expires_in']); 
  88.  
  89. $token->setExtraParams($data); 
  90.  
  91. return $token;