Skip to content

Commit ea87e12

Browse files
committed
feat: store JWT claims in access request
Store the decoded JWT claims in the access request when performing an RFC 7523 request, so they can be inspected after validation.
1 parent 653c812 commit ea87e12

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

access_request.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ type AccessRequest struct {
77
GrantTypes Arguments `json:"grantTypes" gorethink:"grantTypes"`
88
HandledGrantType Arguments `json:"handledGrantType" gorethink:"handledGrantType"`
99

10+
JWTClaims map[string]interface{} `json:"jwt_claims" gorethink:"jwtClaims"`
11+
1012
Request
1113
}
1214

@@ -23,3 +25,11 @@ func NewAccessRequest(session Session) *AccessRequest {
2325
func (a *AccessRequest) GetGrantTypes() Arguments {
2426
return a.GrantTypes
2527
}
28+
29+
func (a *AccessRequest) GetJWTClaims() map[string]interface{} {
30+
return a.JWTClaims
31+
}
32+
33+
func (a *AccessRequest) SetJWTClaims(claims map[string]interface{}) {
34+
a.JWTClaims = claims
35+
}

client_authentication.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ func (f *Fosite) DefaultClientAuthenticationStrategy(ctx context.Context, r *htt
187187
strings.Join(f.Config.GetTokenURLs(ctx), "' or '")))
188188
}
189189

190+
if accessRequest, ok := ctx.Value(AccessRequestContextKey).(*AccessRequest); ok {
191+
accessRequest.SetJWTClaims(claims)
192+
}
193+
190194
return client, nil
191195
} else if len(assertionType) > 0 {
192196
return nil, errorsx.WithStack(ErrInvalidRequest.WithHintf("Unknown client_assertion_type '%s'.", assertionType))

handler/rfc7523/handler.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ func (c *Handler) HandleTokenEndpointRequest(ctx context.Context, request fosite
7070
}
7171

7272
claims := jwt.Claims{}
73-
if err := token.Claims(key, &claims); err != nil {
73+
rawClaims := make(map[string]interface{})
74+
if err := token.Claims(key, &claims, &rawClaims); err != nil {
7475
return errorsx.WithStack(fosite.ErrInvalidGrant.
7576
WithHint("Unable to verify the integrity of the 'assertion' value.").
7677
WithWrap(err).WithDebug(err.Error()),
@@ -115,6 +116,8 @@ func (c *Handler) HandleTokenEndpointRequest(ctx context.Context, request fosite
115116
session.SetExpiresAt(fosite.AccessToken, time.Now().UTC().Add(atLifespan).Round(time.Second))
116117
session.SetSubject(claims.Subject)
117118

119+
request.SetJWTClaims(rawClaims)
120+
118121
return nil
119122
}
120123

oauth2.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,12 @@ type AccessRequester interface {
250250
// GetGrantType returns the requests grant type.
251251
GetGrantTypes() (grantTypes Arguments)
252252

253+
// GetJWTClaims returns the request's decoded JWT claims (RFC 7523).
254+
GetJWTClaims() (claims map[string]interface{})
255+
256+
// SetJWTClaims stores decoded JWT claims for the request (RFC 7523).
257+
SetJWTClaims(claims map[string]interface{})
258+
253259
Requester
254260
}
255261

0 commit comments

Comments
 (0)