From 0439af458f5ecf153fd22d4305dfa64b09527792 Mon Sep 17 00:00:00 2001 From: Gani Georgiev Date: Sat, 31 Dec 2022 14:58:30 +0200 Subject: [PATCH] updated the GitHub provider to ignore extra emails request errors in case of unsufficient custom scopes --- tools/auth/github.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/auth/github.go b/tools/auth/github.go index 8935ef69..b7de2714 100644 --- a/tools/auth/github.go +++ b/tools/auth/github.go @@ -64,8 +64,8 @@ func (p *Github) FetchAuthUser(token *oauth2.Token) (*AuthUser, error) { AccessToken: token.AccessToken, } - // in case user set "Keep my email address private", - // email should be retrieved via extra API request + // in case user has set "Keep my email address private", send an + // **optional** API request to retrieve the verified primary email if user.Email == "" { client := p.Client(token) @@ -75,6 +75,12 @@ func (p *Github) FetchAuthUser(token *oauth2.Token) (*AuthUser, error) { } defer response.Body.Close() + // ignore not found errors caused by unsufficient scope permissions + // (the email field is optional, return the auth user without it) + if response.StatusCode == 404 { + return user, nil + } + content, err := io.ReadAll(response.Body) if err != nil { return user, err