From e88355b3d4cd3b533bf74f765ee35ffcccae8490 Mon Sep 17 00:00:00 2001 From: Jelle Besseling Date: Wed, 30 Dec 2020 21:32:00 +0100 Subject: [PATCH] Use email api call --- src/lib/Hydra/Controller/User.pm | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/lib/Hydra/Controller/User.pm b/src/lib/Hydra/Controller/User.pm index ce48dd44..15fcefe6 100644 --- a/src/lib/Hydra/Controller/User.pm +++ b/src/lib/Hydra/Controller/User.pm @@ -181,11 +181,23 @@ sub github_login :Path('/github-login') Args(0) { my $data = decode_json($response->decoded_content) or die; my $access_token = $data->{access_token} // die "No access_token in response from GitHub."; - $response = $ua->get('https://api.github.com/user', Authorization => "token $access_token"); - error($c, "Did not get a response from GitHub for user info.") unless $response->is_success; + $response = $ua->get('https://api.github.com/user/emails', Accept => 'application/vnd.github.v3+json', Authorization => "token $access_token"); + error($c, "Did not get a response from GitHub for email info.") unless $response->is_success; $data = decode_json($response->decoded_content) or die; - doEmailLogin($self, $c, "github", $data->{email}, $data->{name} // undef); + my $email; + + foreach my $eml (@{$data}) { + $email = $eml->{email} if $eml->{verified} && $eml->{primary}; + print STDERR "$eml->{email}\n"; + } + + print STDERR "$email\n"; + $response = $ua->get('https://api.github.com/user', Authorization => "token $access_token"); + error($c, "Did not get a response from GitHub for user info.") unless $response->is_success; + $data = decode_json($response->decoded_content) or die; + + doEmailLogin($self, $c, "github", $email, $data->{name} // undef); $c->res->redirect($c->uri_for($c->res->cookies->{'after_github'})); }