summaryrefslogtreecommitdiff
path: root/vendor/league/oauth2-client/src/Provider/Github.php
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2019-11-17 20:45:02 +0100
committerAndreas Baumann <mail@andreasbaumann.cc>2019-11-17 20:45:02 +0100
commit8df3db566a3a937b45ebf11adb90d265e6f5e2d4 (patch)
tree4d541098d751d5a9acf8c12f6fb9f308ace066ac /vendor/league/oauth2-client/src/Provider/Github.php
downloadflyspray-8df3db566a3a937b45ebf11adb90d265e6f5e2d4.tar.xz
initial checking of customized version 1.0rc9
Diffstat (limited to 'vendor/league/oauth2-client/src/Provider/Github.php')
-rw-r--r--vendor/league/oauth2-client/src/Provider/Github.php99
1 files changed, 99 insertions, 0 deletions
diff --git a/vendor/league/oauth2-client/src/Provider/Github.php b/vendor/league/oauth2-client/src/Provider/Github.php
new file mode 100644
index 0000000..8182a4e
--- /dev/null
+++ b/vendor/league/oauth2-client/src/Provider/Github.php
@@ -0,0 +1,99 @@
+<?php
+
+namespace League\OAuth2\Client\Provider;
+
+use League\OAuth2\Client\Entity\User;
+use League\OAuth2\Client\Token\AccessToken;
+
+class Github extends AbstractProvider
+{
+ public $responseType = 'string';
+
+ public $authorizationHeader = 'token';
+
+ public $domain = 'https://github.com';
+
+ public $apiDomain = 'https://api.github.com';
+
+ public function urlAuthorize()
+ {
+ return $this->domain.'/login/oauth/authorize';
+ }
+
+ public function urlAccessToken()
+ {
+ return $this->domain.'/login/oauth/access_token';
+ }
+
+ public function urlUserDetails(AccessToken $token)
+ {
+ if ($this->domain === 'https://github.com') {
+ return $this->apiDomain.'/user';
+ }
+ return $this->domain.'/api/v3/user';
+ }
+
+ public function urlUserEmails(AccessToken $token)
+ {
+ if ($this->domain === 'https://github.com') {
+ return $this->apiDomain.'/user/emails';
+ }
+ return $this->domain.'/api/v3/user/emails';
+ }
+
+ public function userDetails($response, AccessToken $token)
+ {
+ $user = new User();
+
+ $name = (isset($response->name)) ? $response->name : null;
+ $email = (isset($response->email)) ? $response->email : null;
+
+ $user->exchangeArray([
+ 'uid' => $response->id,
+ 'nickname' => $response->login,
+ 'name' => $name,
+ 'email' => $email,
+ 'urls' => [
+ 'GitHub' => $this->domain.'/'.$response->login,
+ ],
+ ]);
+
+ return $user;
+ }
+
+ public function userUid($response, AccessToken $token)
+ {
+ return $response->id;
+ }
+
+ public function getUserEmails(AccessToken $token)
+ {
+ $response = $this->fetchUserEmails($token);
+
+ return $this->userEmails(json_decode($response), $token);
+ }
+
+ public function userEmail($response, AccessToken $token)
+ {
+ return isset($response->email) && $response->email ? $response->email : null;
+ }
+
+ public function userEmails($response, AccessToken $token)
+ {
+ return $response;
+ }
+
+ public function userScreenName($response, AccessToken $token)
+ {
+ return $response->name;
+ }
+
+ protected function fetchUserEmails(AccessToken $token)
+ {
+ $url = $this->urlUserEmails($token);
+
+ $headers = $this->getHeaders($token);
+
+ return $this->fetchProviderData($url, $headers);
+ }
+}