feat: add CanGetPrivateClaimsFromRequest interface (#717)
This commit is contained in:
parent
eb2f912c5e
commit
7a767d8568
2 changed files with 11 additions and 1 deletions
|
@ -144,6 +144,12 @@ type CanSetUserinfoFromRequest interface {
|
||||||
SetUserinfoFromRequest(ctx context.Context, userinfo *oidc.UserInfo, request IDTokenRequest, scopes []string) error
|
SetUserinfoFromRequest(ctx context.Context, userinfo *oidc.UserInfo, request IDTokenRequest, scopes []string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CanGetPrivateClaimsFromRequest is an optional additional interface that may be implemented by
|
||||||
|
// implementors of Storage. It allows setting the jwt token claims based on the request.
|
||||||
|
type CanGetPrivateClaimsFromRequest interface {
|
||||||
|
GetPrivateClaimsFromRequest(ctx context.Context, request TokenRequest, restrictedScopes []string) (map[string]any, error)
|
||||||
|
}
|
||||||
|
|
||||||
// Storage is a required parameter for NewOpenIDProvider(). In addition to the
|
// Storage is a required parameter for NewOpenIDProvider(). In addition to the
|
||||||
// embedded interfaces below, if the passed Storage implements ClientCredentialsStorage
|
// embedded interfaces below, if the passed Storage implements ClientCredentialsStorage
|
||||||
// then the grant type "client_credentials" will be supported. In that case, the access
|
// then the grant type "client_credentials" will be supported. In that case, the access
|
||||||
|
|
|
@ -147,7 +147,11 @@ func CreateJWT(ctx context.Context, issuer string, tokenRequest TokenRequest, ex
|
||||||
tokenExchangeRequest,
|
tokenExchangeRequest,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
privateClaims, err = storage.GetPrivateClaimsFromScopes(ctx, tokenRequest.GetSubject(), client.GetID(), removeUserinfoScopes(restrictedScopes))
|
if fromRequest, ok := storage.(CanGetPrivateClaimsFromRequest); ok {
|
||||||
|
privateClaims, err = fromRequest.GetPrivateClaimsFromRequest(ctx, tokenRequest, removeUserinfoScopes(restrictedScopes))
|
||||||
|
} else {
|
||||||
|
privateClaims, err = storage.GetPrivateClaimsFromScopes(ctx, tokenRequest.GetSubject(), client.GetID(), removeUserinfoScopes(restrictedScopes))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue