feat: add ZITADEL project id scope (#4146)

* feat: add ZITADEL project id scope

* update documentation

* documentation

* fix scopes

* change to lowercase
This commit is contained in:
Livio Spring
2022-08-09 09:45:59 +02:00
committed by GitHub
parent 1b5c8677ab
commit 02d2032790
7 changed files with 71 additions and 73 deletions

View File

@@ -1,9 +1,11 @@
package domain
import (
"context"
"strings"
"time"
"github.com/zitadel/zitadel/internal/api/authz"
es_models "github.com/zitadel/zitadel/internal/eventstore/v1/models"
)
@@ -20,11 +22,16 @@ type Token struct {
PreferredLanguage string
}
func AddAudScopeToAudience(audience, scopes []string) []string {
func AddAudScopeToAudience(ctx context.Context, audience, scopes []string) []string {
for _, scope := range scopes {
if strings.HasPrefix(scope, ProjectIDScope) && strings.HasSuffix(scope, AudSuffix) {
audience = append(audience, strings.TrimSuffix(strings.TrimPrefix(scope, ProjectIDScope), AudSuffix))
if !(strings.HasPrefix(scope, ProjectIDScope) && strings.HasSuffix(scope, AudSuffix)) {
continue
}
projectID := strings.TrimSuffix(strings.TrimPrefix(scope, ProjectIDScope), AudSuffix)
if projectID == ProjectIDScopeZITADEL {
projectID = authz.GetInstance(ctx).ProjectID()
}
audience = append(audience, projectID)
}
return audience
}