2023-02-08 08:06:34 +00:00
|
|
|
package oidc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2023-10-17 15:19:51 +00:00
|
|
|
"github.com/zitadel/oidc/v3/pkg/oidc"
|
|
|
|
"github.com/zitadel/oidc/v3/pkg/op"
|
2023-02-08 08:06:34 +00:00
|
|
|
|
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
2024-01-18 06:10:49 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/telemetry/tracing"
|
2023-12-08 14:30:55 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
2023-02-08 08:06:34 +00:00
|
|
|
)
|
|
|
|
|
2024-01-18 06:10:49 +00:00
|
|
|
func (o *OPStorage) JWTProfileTokenType(ctx context.Context, request op.TokenRequest) (_ op.AccessTokenType, err error) {
|
|
|
|
ctx, span := tracing.NewSpan(ctx)
|
|
|
|
defer func() {
|
|
|
|
err = oidcError(err)
|
|
|
|
span.EndWithError(err)
|
|
|
|
}()
|
|
|
|
|
2023-02-08 08:06:34 +00:00
|
|
|
mapJWTProfileScopesToAudience(ctx, request)
|
2023-11-21 12:11:38 +00:00
|
|
|
user, err := o.query.GetUserByID(ctx, false, request.GetSubject())
|
2023-02-08 08:06:34 +00:00
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
// the user should always be a machine, but let's just be sure
|
|
|
|
if user.Machine == nil {
|
2023-12-08 14:30:55 +00:00
|
|
|
return 0, zerrors.ThrowInvalidArgument(nil, "OIDC-jk26S", "invalid client type")
|
2023-02-08 08:06:34 +00:00
|
|
|
}
|
|
|
|
return accessTokenTypeToOIDC(user.Machine.AccessTokenType), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func mapJWTProfileScopesToAudience(ctx context.Context, request op.TokenRequest) {
|
|
|
|
// the request should always be a JWTTokenRequest, but let's make sure
|
|
|
|
jwt, ok := request.(*oidc.JWTTokenRequest)
|
|
|
|
if !ok {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
jwt.Audience = domain.AddAudScopeToAudience(ctx, jwt.Audience, jwt.Scopes)
|
|
|
|
}
|