mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 21:17:32 +00:00
feat(actions): add fields to complement token flow (#5336)
* deprecated `ctx.v1.userinfo`-field in "pre userinfo creation" trigger in favour of `ctx.v1.claims`. The trigger now behaves the same as "pre access token creation" * added `ctx.v1.claims` to "complement tokens" flow * added `ctx.v1.grants` to "complement tokens" flow * document `ctx.v1.getUser()` in "complement tokens" flow * feat(actions): add getUser() and grant * map user grants * map claims * feat(actions): claims in complement token ctx * docs(actions): add new fields of complement token * docs(actions): additions to complement token * docs(actions): correct field names
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
package object
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/dop251/goja"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/actions"
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/query"
|
||||
)
|
||||
|
||||
type UserGrants struct {
|
||||
@@ -17,6 +20,32 @@ type UserGrant struct {
|
||||
Roles []string
|
||||
}
|
||||
|
||||
type userGrantList struct {
|
||||
Count uint64
|
||||
Sequence uint64
|
||||
Timestamp time.Time
|
||||
Grants []*userGrant
|
||||
}
|
||||
|
||||
type userGrant struct {
|
||||
Id string
|
||||
ProjectGrantId string
|
||||
State domain.UserGrantState
|
||||
UserGrantResourceOwner string
|
||||
UserGrantResourceOwnerName string
|
||||
|
||||
CreationDate time.Time
|
||||
ChangeDate time.Time
|
||||
Sequence uint64
|
||||
|
||||
UserId string
|
||||
UserResourceOwner string
|
||||
Roles []string
|
||||
|
||||
ProjectId string
|
||||
ProjectName string
|
||||
}
|
||||
|
||||
func AppendGrantFunc(userGrants *UserGrants) func(c *actions.FieldConfig) func(call goja.FunctionCall) goja.Value {
|
||||
return func(c *actions.FieldConfig) func(call goja.FunctionCall) goja.Value {
|
||||
return func(call goja.FunctionCall) goja.Value {
|
||||
@@ -29,6 +58,51 @@ func AppendGrantFunc(userGrants *UserGrants) func(c *actions.FieldConfig) func(c
|
||||
}
|
||||
}
|
||||
|
||||
func UserGrantsFromQuery(c *actions.FieldConfig, userGrants *query.UserGrants) goja.Value {
|
||||
grantList := &userGrantList{
|
||||
Count: userGrants.Count,
|
||||
Sequence: userGrants.Sequence,
|
||||
Timestamp: userGrants.Timestamp,
|
||||
Grants: make([]*userGrant, len(userGrants.UserGrants)),
|
||||
}
|
||||
|
||||
for i, grant := range userGrants.UserGrants {
|
||||
grantList.Grants[i] = &userGrant{
|
||||
Id: grant.ID,
|
||||
ProjectGrantId: grant.GrantID,
|
||||
State: grant.State,
|
||||
CreationDate: grant.CreationDate,
|
||||
ChangeDate: grant.ChangeDate,
|
||||
Sequence: grant.Sequence,
|
||||
UserId: grant.UserID,
|
||||
Roles: grant.Roles,
|
||||
UserResourceOwner: grant.UserResourceOwner,
|
||||
UserGrantResourceOwner: grant.ResourceOwner,
|
||||
UserGrantResourceOwnerName: grant.OrgName,
|
||||
ProjectId: grant.ProjectID,
|
||||
ProjectName: grant.ProjectName,
|
||||
}
|
||||
}
|
||||
|
||||
return c.Runtime.ToValue(grantList)
|
||||
}
|
||||
|
||||
func UserGrantsToDomain(userID string, actionUserGrants []UserGrant) []*domain.UserGrant {
|
||||
if actionUserGrants == nil {
|
||||
return nil
|
||||
}
|
||||
userGrants := make([]*domain.UserGrant, len(actionUserGrants))
|
||||
for i, grant := range actionUserGrants {
|
||||
userGrants[i] = &domain.UserGrant{
|
||||
UserID: userID,
|
||||
ProjectID: grant.ProjectID,
|
||||
ProjectGrantID: grant.ProjectGrantID,
|
||||
RoleKeys: grant.Roles,
|
||||
}
|
||||
}
|
||||
return userGrants
|
||||
}
|
||||
|
||||
func mapObjectToGrant(object *goja.Object, grant *UserGrant) {
|
||||
for _, key := range object.Keys() {
|
||||
switch key {
|
||||
@@ -50,19 +124,3 @@ func mapObjectToGrant(object *goja.Object, grant *UserGrant) {
|
||||
panic("projectId not set")
|
||||
}
|
||||
}
|
||||
|
||||
func UserGrantsToDomain(userID string, actionUserGrants []UserGrant) []*domain.UserGrant {
|
||||
if actionUserGrants == nil {
|
||||
return nil
|
||||
}
|
||||
userGrants := make([]*domain.UserGrant, len(actionUserGrants))
|
||||
for i, grant := range actionUserGrants {
|
||||
userGrants[i] = &domain.UserGrant{
|
||||
UserID: userID,
|
||||
ProjectID: grant.ProjectID,
|
||||
ProjectGrantID: grant.ProjectGrantID,
|
||||
RoleKeys: grant.Roles,
|
||||
}
|
||||
}
|
||||
return userGrants
|
||||
}
|
||||
|
Reference in New Issue
Block a user