2021-02-08 11:30:30 +01:00
|
|
|
package domain
|
|
|
|
|
|
|
|
import (
|
2022-08-09 09:45:59 +02:00
|
|
|
"context"
|
2021-02-18 14:48:27 +01:00
|
|
|
"strings"
|
2021-11-03 08:35:24 +01:00
|
|
|
|
2022-08-09 09:45:59 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/api/authz"
|
2021-02-08 11:30:30 +01:00
|
|
|
)
|
|
|
|
|
2022-08-09 09:45:59 +02:00
|
|
|
func AddAudScopeToAudience(ctx context.Context, audience, scopes []string) []string {
|
2021-02-18 14:48:27 +01:00
|
|
|
for _, scope := range scopes {
|
2022-08-09 09:45:59 +02:00
|
|
|
if !(strings.HasPrefix(scope, ProjectIDScope) && strings.HasSuffix(scope, AudSuffix)) {
|
|
|
|
continue
|
2021-02-18 14:48:27 +01:00
|
|
|
}
|
2022-08-09 09:45:59 +02:00
|
|
|
projectID := strings.TrimSuffix(strings.TrimPrefix(scope, ProjectIDScope), AudSuffix)
|
|
|
|
if projectID == ProjectIDScopeZITADEL {
|
|
|
|
projectID = authz.GetInstance(ctx).ProjectID()
|
|
|
|
}
|
2023-02-08 09:06:34 +01:00
|
|
|
audience = addProjectID(audience, projectID)
|
2021-02-18 14:48:27 +01:00
|
|
|
}
|
|
|
|
return audience
|
|
|
|
}
|
2023-02-08 09:06:34 +01:00
|
|
|
|
|
|
|
func addProjectID(audience []string, projectID string) []string {
|
|
|
|
for _, a := range audience {
|
|
|
|
if a == projectID {
|
|
|
|
return audience
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return append(audience, projectID)
|
|
|
|
}
|
2024-03-20 12:18:46 +02:00
|
|
|
|
|
|
|
//go:generate enumer -type TokenReason -transform snake -trimprefix TokenReason -json
|
|
|
|
type TokenReason int
|
|
|
|
|
|
|
|
const (
|
|
|
|
TokenReasonUnspecified TokenReason = iota
|
|
|
|
TokenReasonAuthRequest
|
|
|
|
TokenReasonRefresh
|
|
|
|
TokenReasonJWTProfile
|
|
|
|
TokenReasonClientCredentials
|
|
|
|
TokenReasonExchange
|
|
|
|
TokenReasonImpersonation
|
|
|
|
)
|
|
|
|
|
|
|
|
type TokenActor struct {
|
|
|
|
Actor *TokenActor `json:"actor,omitempty"`
|
|
|
|
UserID string `json:"user_id,omitempty"`
|
|
|
|
Issuer string `json:"issuer,omitempty"`
|
|
|
|
}
|