Skip to content

Commit 62c62f7

Browse files
committed
refactor: align struct fields with OpenID Connect specification
This change adds Name, Picture, GivenName, FamilyName in the UserInfo structure to solve the problem of not being able to obtain user information in some scenarios
1 parent 35b8e03 commit 62c62f7

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

oidc/oidc.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,10 @@ type UserInfo struct {
325325
Profile string `json:"profile"`
326326
Email string `json:"email"`
327327
EmailVerified bool `json:"email_verified"`
328+
Name string `json:"name"`
329+
Picture string `json:"picture"`
330+
GivenName string `json:"given_name"`
331+
FamilyName string `json:"family_name"`
328332

329333
claims []byte
330334
}
@@ -337,6 +341,12 @@ type userInfoRaw struct {
337341
// https://forums.aws.amazon.com/thread.jspa?messageID=949441&#949441 and
338342
// https://discuss.elastic.co/t/openid-error-after-authenticating-against-aws-cognito/206018/11
339343
EmailVerified stringAsBool `json:"email_verified"`
344+
// Align the fields in the OpenID example
345+
//https://openid.net/specs/openid-connect-core-1_0.html#UserInfoResponse
346+
Name string `json:"name"`
347+
Picture string `json:"picture"`
348+
GivenName string `json:"given_name"`
349+
FamilyName string `json:"family_name"`
340350
}
341351

342352
// Claims unmarshals the raw JSON object claims into the provided object.
@@ -397,6 +407,10 @@ func (p *Provider) UserInfo(ctx context.Context, tokenSource oauth2.TokenSource)
397407
Email: userInfo.Email,
398408
EmailVerified: bool(userInfo.EmailVerified),
399409
claims: body,
410+
Name: userInfo.Name,
411+
Picture: userInfo.Picture,
412+
GivenName: userInfo.GivenName,
413+
FamilyName: userInfo.FamilyName,
400414
}, nil
401415
}
402416

0 commit comments

Comments
 (0)