From 6854cb3f4d8219cf1829e32122eb2502a916eae9 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sat, 1 Feb 2020 09:05:48 +0100 Subject: initial checkin --- includes/GithubProvider.php | 60 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 includes/GithubProvider.php (limited to 'includes/GithubProvider.php') diff --git a/includes/GithubProvider.php b/includes/GithubProvider.php new file mode 100644 index 0000000..5639383 --- /dev/null +++ b/includes/GithubProvider.php @@ -0,0 +1,60 @@ +email) { + $emails = $this->fetchUserEmails($token); + $emails = json_decode($emails); + $email = null; + + foreach ($emails as $email) { + if ($email->primary) { + $email = $email->email; + break; + } + } + + $user->email = $email; + } + + return $user; + } + + protected function fetchUserEmails(AccessToken $token) + { + $url = "https://api.github.com/user/emails?access_token={$token}"; + + try { + + $client = $this->getHttpClient(); + $client->setBaseUrl($url); + + if ($this->headers) { + $client->setDefaultOption('headers', $this->headers); + } + + $request = $client->get()->send(); + $response = $request->getBody(); + + } catch (BadResponseException $e) { + // @codeCoverageIgnoreStart + $raw_response = explode("\n", $e->getResponse()); + throw new IDPException(end($raw_response)); + // @codeCoverageIgnoreEnd + } + + return $response; + } +} \ No newline at end of file -- cgit v1.2.3-70-g09d2