@@ -17,13 +17,7 @@ import (
1717 "golang.org/x/oauth2/endpoints"
1818)
1919
20- var GoogleOAuthScopes = []string {"https://www.googleapis.com/auth/userinfo.email" , "https://www.googleapis.com/auth/userinfo.profile" }
21-
22- type GoogleUserInfoResponse struct {
23- Email string `json:"email"`
24- Name string `json:"name"`
25- Id string `json:"id"`
26- }
20+ var GoogleOAuthScopes = []string {"openid" , "email" , "profile" }
2721
2822type GoogleOAuthService struct {
2923 config oauth2.Config
@@ -92,7 +86,7 @@ func (google *GoogleOAuthService) Userinfo() (config.Claims, error) {
9286
9387 client := google .config .Client (google .context , google .token )
9488
95- res , err := client .Get ("https://www .googleapis.com/userinfo/v2/me " )
89+ res , err := client .Get ("https://openidconnect .googleapis.com/v1/userinfo " )
9690 if err != nil {
9791 return config.Claims {}, err
9892 }
@@ -107,19 +101,12 @@ func (google *GoogleOAuthService) Userinfo() (config.Claims, error) {
107101 return config.Claims {}, err
108102 }
109103
110- var userInfo GoogleUserInfoResponse
111-
112- err = json .Unmarshal (body , & userInfo )
104+ err = json .Unmarshal (body , & user )
113105 if err != nil {
114106 return config.Claims {}, err
115107 }
116108
117- user .PreferredUsername = strings .Split (userInfo .Email , "@" )[0 ]
118- user .Name = userInfo .Name
119- user .Email = userInfo .Email
120-
121- // We can use the id as the sub
122- user .Sub = userInfo .Id
109+ user .PreferredUsername = strings .SplitN (user .Email , "@" , 2 )[0 ]
123110
124111 return user , nil
125112}
0 commit comments