feat: add CanSetUserinfoFromRequest interface (#347)
This commit is contained in:
parent
edc9a1f60d
commit
c9555c7f1b
4 changed files with 38 additions and 5 deletions
|
@ -113,6 +113,8 @@ type OPStorage interface {
|
|||
// handle the current request.
|
||||
GetClientByClientID(ctx context.Context, clientID string) (Client, error)
|
||||
AuthorizeClientIDSecret(ctx context.Context, clientID, clientSecret string) error
|
||||
// SetUserinfoFromScopes is deprecated and should have an empty implementation for now.
|
||||
// Implement SetUserinfoFromRequest instead.
|
||||
SetUserinfoFromScopes(ctx context.Context, userinfo *oidc.UserInfo, userID, clientID string, scopes []string) error
|
||||
SetUserinfoFromToken(ctx context.Context, userinfo *oidc.UserInfo, tokenID, subject, origin string) error
|
||||
SetIntrospectionFromToken(ctx context.Context, userinfo *oidc.IntrospectionResponse, tokenID, subject, clientID string) error
|
||||
|
@ -127,6 +129,13 @@ type JWTProfileTokenStorage interface {
|
|||
JWTProfileTokenType(ctx context.Context, request TokenRequest) (AccessTokenType, error)
|
||||
}
|
||||
|
||||
// CanSetUserinfoFromRequest is an optional additional interface that may be implemented by
|
||||
// implementors of Storage. It allows additional data to be set in id_tokens based on the
|
||||
// request.
|
||||
type CanSetUserinfoFromRequest interface {
|
||||
SetUserinfoFromRequest(ctx context.Context, userinfo *oidc.UserInfo, request IDTokenRequest, scopes []string) error
|
||||
}
|
||||
|
||||
// Storage is a required parameter for NewOpenIDProvider(). In addition to the
|
||||
// embedded interfaces below, if the passed Storage implements ClientCredentialsStorage
|
||||
// then the grant type "client_credentials" will be supported. In that case, the access
|
||||
|
|
|
@ -190,6 +190,12 @@ func CreateIDToken(ctx context.Context, issuer string, request IDTokenRequest, v
|
|||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if fromRequest, ok := storage.(CanSetUserinfoFromRequest); ok {
|
||||
err := fromRequest.SetUserinfoFromRequest(ctx, userInfo, request, scopes)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
claims.SetUserInfo(userInfo)
|
||||
}
|
||||
if code != "" {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue