[ Index ] |
PHP Cross Reference of phpBB-3.1.12-deutsch |
[Summary view] [Print] [Text view]
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 class GitHub extends AbstractService 14 { 15 /** 16 * Defined scopes, see http://developer.github.com/v3/oauth/ for definitions. 17 */ 18 19 /** 20 * Public read-only access (includes public user profile info, public repo info, and gists) 21 */ 22 const SCOPE_READONLY = ''; 23 24 /** 25 * Read/write access to profile info only. 26 * 27 * Includes SCOPE_USER_EMAIL and SCOPE_USER_FOLLOW. 28 */ 29 const SCOPE_USER = 'user'; 30 31 /** 32 * Read access to a user’s email addresses. 33 */ 34 const SCOPE_USER_EMAIL = 'user:email'; 35 36 /** 37 * Access to follow or unfollow other users. 38 */ 39 const SCOPE_USER_FOLLOW = 'user:follow'; 40 41 /** 42 * Read/write access to public repos and organizations. 43 */ 44 const SCOPE_PUBLIC_REPO = 'public_repo'; 45 46 /** 47 * Read/write access to public and private repos and organizations. 48 * 49 * Includes SCOPE_REPO_STATUS. 50 */ 51 const SCOPE_REPO = 'repo'; 52 53 /** 54 * Read/write access to public and private repository commit statuses. This scope is only necessary to grant other 55 * users or services access to private repository commit statuses without granting access to the code. The repo and 56 * public_repo scopes already include access to commit status for private and public repositories, respectively. 57 */ 58 const SCOPE_REPO_STATUS = 'repo:status'; 59 60 /** 61 * Delete access to adminable repositories. 62 */ 63 const SCOPE_DELETE_REPO = 'delete_repo'; 64 65 /** 66 * Read access to a user’s notifications. repo is accepted too. 67 */ 68 const SCOPE_NOTIFICATIONS = 'notifications'; 69 70 /** 71 * Write access to gists. 72 */ 73 const SCOPE_GIST = 'gist'; 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 89 /** 90 * {@inheritdoc} 91 */ 92 public function getAuthorizationEndpoint() 93 { 94 return new Uri('https://github.com/login/oauth/authorize'); 95 } 96 97 /** 98 * {@inheritdoc} 99 */ 100 public function getAccessTokenEndpoint() 101 { 102 return new Uri('https://github.com/login/oauth/access_token'); 103 } 104 105 /** 106 * {@inheritdoc} 107 */ 108 protected function getAuthorizationMethod() 109 { 110 return static::AUTHORIZATION_METHOD_QUERY_STRING; 111 } 112 113 /** 114 * {@inheritdoc} 115 */ 116 protected function parseAccessTokenResponse($responseBody) 117 { 118 $data = json_decode($responseBody, true); 119 120 if (null === $data || !is_array($data)) { 121 throw new TokenResponseException('Unable to parse response.'); 122 } elseif (isset($data['error'])) { 123 throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"'); 124 } 125 126 $token = new StdOAuth2Token(); 127 $token->setAccessToken($data['access_token']); 128 // Github tokens evidently never expire... 129 $token->setEndOfLife(StdOAuth2Token::EOL_NEVER_EXPIRES); 130 unset($data['access_token']); 131 132 $token->setExtraParams($data); 133 134 return $token; 135 } 136 137 /** 138 * Used to configure response type -- we want JSON from github, default is query string format 139 * 140 * @return array 141 */ 142 protected function getExtraOAuthHeaders() 143 { 144 return array('Accept' => 'application/json'); 145 } 146 147 /** 148 * Required for GitHub API calls. 149 * 150 * @return array 151 */ 152 protected function getExtraApiHeaders() 153 { 154 return array('Accept' => 'application/vnd.github.beta+json'); 155 } 156 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Jan 11 00:25:41 2018 | Cross-referenced by PHPXref 0.7.1 |