chore: add debug logs for OIDC responses (#6641)

This commit is contained in:
Colin Adler 2023-03-16 19:33:45 -05:00 committed by GitHub
parent ffca3a5fb3
commit 1c05b46b02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 0 deletions

View File

@ -569,6 +569,20 @@ func (api *API) userOIDC(rw http.ResponseWriter, r *http.Request) {
return
}
// Log all of the field names returned in the ID token claims, and the
// userinfo returned from the provider.
{
fields := make([]string, 0, len(claims))
for f := range claims {
fields = append(fields, f)
}
api.Logger.Debug(ctx, "got oidc claims",
slog.F("user_info", userInfo),
slog.F("claim_fields", fields),
)
}
usernameRaw, ok := claims[api.OIDCConfig.UsernameField]
var username string
if ok {
@ -624,6 +638,11 @@ func (api *API) userOIDC(rw http.ResponseWriter, r *http.Request) {
// Convert the []interface{} we get to a []string.
groupsInterface, ok := groupsRaw.([]interface{})
if ok {
api.Logger.Debug(ctx, "groups returned in oidc claims",
slog.F("len", len(groupsInterface)),
slog.F("groups", groupsInterface),
)
for _, groupInterface := range groupsInterface {
group, ok := groupInterface.(string)
if !ok {
@ -634,6 +653,10 @@ func (api *API) userOIDC(rw http.ResponseWriter, r *http.Request) {
}
groups = append(groups, group)
}
} else {
api.Logger.Debug(ctx, "groups field was an unknown type",
slog.F("type", fmt.Sprintf("%T", groupsRaw)),
)
}
}
}