Skip to content

Commit ecc8f2b

Browse files
slingamnGiteaBot
andauthored
add username to OIDC introspection response (#31688)
This field is specified as optional here: https://datatracker.ietf.org/doc/html/rfc7662#section-2.2 It's used by some OIDC integrations, e.g. https://emersion.fr/blog/2022/irc-and-oauth2/ Co-authored-by: Giteabot <[email protected]>
1 parent bae87df commit ecc8f2b

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

routers/web/auth/oauth.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,9 @@ func IntrospectOAuth(ctx *context.Context) {
353353
}
354354

355355
var response struct {
356-
Active bool `json:"active"`
357-
Scope string `json:"scope,omitempty"`
356+
Active bool `json:"active"`
357+
Scope string `json:"scope,omitempty"`
358+
Username string `json:"username,omitempty"`
358359
jwt.RegisteredClaims
359360
}
360361

@@ -371,6 +372,9 @@ func IntrospectOAuth(ctx *context.Context) {
371372
response.Audience = []string{app.ClientID}
372373
response.Subject = fmt.Sprint(grant.UserID)
373374
}
375+
if user, err := user_model.GetUserByID(ctx, grant.UserID); err == nil {
376+
response.Username = user.Name
377+
}
374378
}
375379
}
376380

tests/integration/oauth_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,12 +450,14 @@ func TestOAuthIntrospection(t *testing.T) {
450450
req.Header.Add("Authorization", "Basic ZGE3ZGEzYmEtOWExMy00MTY3LTg1NmYtMzg5OWRlMGIwMTM4OjRNSzhOYTZSNTVzbWRDWTBXdUNDdW1aNmhqUlBuR1k1c2FXVlJISGpKaUE9")
451451
resp = MakeRequest(t, req, http.StatusOK)
452452
type introspectResponse struct {
453-
Active bool `json:"active"`
454-
Scope string `json:"scope,omitempty"`
453+
Active bool `json:"active"`
454+
Scope string `json:"scope,omitempty"`
455+
Username string `json:"username"`
455456
}
456457
introspectParsed := new(introspectResponse)
457458
assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), introspectParsed))
458459
assert.True(t, introspectParsed.Active)
460+
assert.Equal(t, "user1", introspectParsed.Username)
459461

460462
// successful request with a valid client_id/client_secret, but an invalid token
461463
req = NewRequestWithValues(t, "POST", "/login/oauth/introspect", map[string]string{

0 commit comments

Comments
 (0)