Skip to content

Commit 395e2e2

Browse files
committed
fix: update scope for apple login
1 parent 6335084 commit 395e2e2

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

server/handlers/oauth_callback.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -482,15 +482,26 @@ func processAppleUserInfo(code string) (models.User, error) {
482482
}
483483
fmt.Println("=> decoded claims data", decodedClaimsData)
484484

485-
claims := map[string]string{}
485+
claims := make(map[string]interface{})
486486
err = json.Unmarshal([]byte(decodedClaimsData), &claims)
487487
if err != nil {
488488
log.Debug("Failed to unmarshal claims data: ", err)
489489
return user, fmt.Errorf("failed to unmarshal claims data: %s", err.Error())
490490
}
491-
fmt.Println("=> claims map:", claims)
492-
email := claims["email"]
493-
user.Email = email
491+
492+
fmt.Println("=> claims", claims)
493+
494+
if val, ok := claims["email"]; !ok {
495+
log.Debug("Failed to extract email from claims")
496+
return user, fmt.Errorf("unable to extract email")
497+
} else {
498+
user.Email = val.(string)
499+
}
500+
501+
if val, ok := claims["name"]; ok {
502+
givenName := val.(string)
503+
user.GivenName = &givenName
504+
}
494505

495506
return user, err
496507
}

server/oauth/oauth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func InitOAuth() error {
130130
AuthURL: "https://appleid.apple.com/auth/authorize",
131131
TokenURL: "https://appleid.apple.com/auth/token",
132132
},
133-
Scopes: []string{"email"},
133+
Scopes: []string{"name", "email"},
134134
}
135135
}
136136

0 commit comments

Comments
 (0)