Skip to content

Commit 98c0b47

Browse files
authored
fix(google): preserve username when absent in refresh token (#4758)
Google sometimes does not return username and other claims during token refresh, which is correct according to OIDC spec. Instead of calling the userinfo endpoint (which Google throttles more aggressively), preserve the previous username if absent in the refreshed ID token. This fix is specific to the Google connector and does not modify the general refresh flow. Fixes #4458 Signed-off-by: Hisam Fahri <iam@hisamafahri.com>
1 parent d7ba134 commit 98c0b47

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

connector/google/google.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,15 @@ func (c *googleConnector) createIdentity(ctx context.Context, identity connector
247247
return identity, fmt.Errorf("oidc: failed to decode claims: %v", err)
248248
}
249249

250+
// Google sometimes do not return username and other claims. It is correct, according to OIDC spec.
251+
// One option to solve this is to call the user endpoint, but Google throttles it more aggressive than
252+
// the token endpoint. For concurrent refreshes it is an unwanted behavior.
253+
// As a tradeoff, dex preserves previous username and preferred username if absent in the ide token
254+
// as a way to keep the claims and do not call the userinfo endpoint.
255+
if claims.Username == "" {
256+
claims.Username = identity.Username
257+
}
258+
250259
if len(c.hostedDomains) > 0 {
251260
found := false
252261
for _, domain := range c.hostedDomains {

0 commit comments

Comments
 (0)