OAuthOAuth2ServiceGitHub

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

Defined (1)

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

/lib/PHPoAuthLib/src/OAuth/OAuth2/Service/GitHub.php  
  1. class GitHub extends AbstractService 
  2. /** 
  3. * Defined scopes, see http://developer.github.com/v3/oauth/ for definitions. 
  4. */ 
  5.  
  6. /** 
  7. * Public read-only access (includes public user profile info, public repo info, and gists) 
  8. */ 
  9. const SCOPE_READONLY = ''; 
  10.  
  11. /** 
  12. * Read/write access to profile info only. 
  13. * Includes SCOPE_USER_EMAIL and SCOPE_USER_FOLLOW. 
  14. */ 
  15. const SCOPE_USER = 'user'; 
  16.  
  17. /** 
  18. * Read access to a user*s email addresses. 
  19. */ 
  20. const SCOPE_USER_EMAIL = 'user:email'; 
  21.  
  22. /** 
  23. * Access to follow or unfollow other users. 
  24. */ 
  25. const SCOPE_USER_FOLLOW = 'user:follow'; 
  26.  
  27. /** 
  28. * Read/write access to public repos and organizations. 
  29. */ 
  30. const SCOPE_PUBLIC_REPO = 'public_repo'; 
  31.  
  32. /** 
  33. * Read/write access to public and private repos and organizations. 
  34. * Includes SCOPE_REPO_STATUS. 
  35. */ 
  36. const SCOPE_REPO = 'repo'; 
  37.  
  38. /** 
  39. * Read/write access to public and private repository commit statuses. This scope is only necessary to grant other 
  40. * users or services access to private repository commit statuses without granting access to the code. The repo and 
  41. * public_repo scopes already include access to commit status for private and public repositories, respectively. 
  42. */ 
  43. const SCOPE_REPO_STATUS = 'repo:status'; 
  44.  
  45. /** 
  46. * Delete access to adminable repositories. 
  47. */ 
  48. const SCOPE_DELETE_REPO = 'delete_repo'; 
  49.  
  50. /** 
  51. * Read access to a user*s notifications. repo is accepted too. 
  52. */ 
  53. const SCOPE_NOTIFICATIONS = 'notifications'; 
  54.  
  55. /** 
  56. * Write access to gists. 
  57. */ 
  58. const SCOPE_GIST = 'gist'; 
  59.  
  60. /** 
  61. * Grants read and ping access to hooks in public or private repositories. 
  62. */ 
  63. const SCOPE_HOOKS_READ = 'read:repo_hook'; 
  64.  
  65. /** 
  66. * Grants read, write, and ping access to hooks in public or private repositories. 
  67. */ 
  68. const SCOPE_HOOKS_WRITE = 'write:repo_hook'; 
  69.  
  70. /** 
  71. * Grants read, write, ping, and delete access to hooks in public or private repositories. 
  72. */ 
  73. const SCOPE_HOOKS_ADMIN = 'admin:repo_hook'; 
  74.  
  75. public function __construct( 
  76. CredentialsInterface $credentials,  
  77. ClientInterface $httpClient,  
  78. TokenStorageInterface $storage,  
  79. $scopes = array(),  
  80. UriInterface $baseApiUri = null 
  81. ) { 
  82. parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri); 
  83.  
  84. if (null === $baseApiUri) { 
  85. $this->baseApiUri = new Uri('https://api.github.com/'); 
  86.  
  87. /** 
  88. * {@inheritdoc} 
  89. */ 
  90. public function getAuthorizationEndpoint() 
  91. return new Uri('https://github.com/login/oauth/authorize'); 
  92.  
  93. /** 
  94. * {@inheritdoc} 
  95. */ 
  96. public function getAccessTokenEndpoint() 
  97. return new Uri('https://github.com/login/oauth/access_token'); 
  98.  
  99. /** 
  100. * {@inheritdoc} 
  101. */ 
  102. protected function getAuthorizationMethod() 
  103. return static::AUTHORIZATION_METHOD_QUERY_STRING; 
  104.  
  105. /** 
  106. * {@inheritdoc} 
  107. */ 
  108. protected function parseAccessTokenResponse($responseBody) 
  109. $data = json_decode($responseBody, true); 
  110.  
  111. if (null === $data || !is_array($data)) { 
  112. throw new TokenResponseException('Unable to parse response.'); 
  113. } elseif (isset($data['error'])) { 
  114. throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"'); 
  115.  
  116. $token = new StdOAuth2Token(); 
  117. $token->setAccessToken($data['access_token']); 
  118. // Github tokens evidently never expire... 
  119. $token->setEndOfLife(StdOAuth2Token::EOL_NEVER_EXPIRES); 
  120. unset($data['access_token']); 
  121.  
  122. $token->setExtraParams($data); 
  123.  
  124. return $token; 
  125.  
  126. /** 
  127. * Used to configure response type -- we want JSON from github, default is query string format 
  128. * @return array 
  129. */ 
  130. protected function getExtraOAuthHeaders() 
  131. return array('Accept' => 'application/json'); 
  132.  
  133. /** 
  134. * Required for GitHub API calls. 
  135. * @return array 
  136. */ 
  137. protected function getExtraApiHeaders() 
  138. return array('Accept' => 'application/vnd.github.beta+json');