From 395e2e2a856b6425c2f18548076cc8a14b79b51b Mon Sep 17 00:00:00 2001 From: Lakhan Samani Date: Tue, 14 Jun 2022 12:35:23 +0530 Subject: [PATCH] fix: update scope for apple login --- server/handlers/oauth_callback.go | 19 +++++++++++++++---- server/oauth/oauth.go | 2 +- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/server/handlers/oauth_callback.go b/server/handlers/oauth_callback.go index e8ed5b0..28a28d6 100644 --- a/server/handlers/oauth_callback.go +++ b/server/handlers/oauth_callback.go @@ -482,15 +482,26 @@ func processAppleUserInfo(code string) (models.User, error) { } fmt.Println("=> decoded claims data", decodedClaimsData) - claims := map[string]string{} + claims := make(map[string]interface{}) err = json.Unmarshal([]byte(decodedClaimsData), &claims) if err != nil { log.Debug("Failed to unmarshal claims data: ", err) return user, fmt.Errorf("failed to unmarshal claims data: %s", err.Error()) } - fmt.Println("=> claims map:", claims) - email := claims["email"] - user.Email = email + + fmt.Println("=> claims", claims) + + if val, ok := claims["email"]; !ok { + log.Debug("Failed to extract email from claims") + return user, fmt.Errorf("unable to extract email") + } else { + user.Email = val.(string) + } + + if val, ok := claims["name"]; ok { + givenName := val.(string) + user.GivenName = &givenName + } return user, err } diff --git a/server/oauth/oauth.go b/server/oauth/oauth.go index 2cb7a3b..cbfac89 100644 --- a/server/oauth/oauth.go +++ b/server/oauth/oauth.go @@ -130,7 +130,7 @@ func InitOAuth() error { AuthURL: "https://appleid.apple.com/auth/authorize", TokenURL: "https://appleid.apple.com/auth/token", }, - Scopes: []string{"email"}, + Scopes: []string{"name", "email"}, } }