feat(api): allow specifying access token type for user of type machine (#11599)

# Which Problems Are Solved

The user service v2 didn't allow the specify or change the access token
type for users of type machine and referred to using the management API,
which in return was already deprecated and linked to the user service.

# How the Problems Are Solved

Added a possibility to specify the access token type in the creation and
update request.

# Additional Changes

None

# Additional Context

- closes #10850
- requires backport to v4.x

---------

Co-authored-by: Copilot <[email protected]>
This commit is contained in:
Livio Spring
2026-02-19 05:05:19 +00:00
committed by GitHub
co-authored by Copilot
parent a31e435491
commit e41b70b1e3
6 changed files with 176 additions and 18 deletions
+12 -5
View File
@@ -11,11 +11,12 @@ import (
)
type ChangeMachine struct {
ID string
ResourceOwner string
Username *string
Name *string
Description *string
ID string
ResourceOwner string
Username *string
Name *string
Description *string
AccessTokenType *domain.OIDCTokenType
// Details are set after a successful execution of the command
Details *domain.ObjectDetails
@@ -31,6 +32,9 @@ func (h *ChangeMachine) Changed() bool {
if h.Description != nil {
return true
}
if h.AccessTokenType != nil {
return true
}
return false
}
@@ -64,6 +68,9 @@ func (c *Commands) ChangeUserMachine(ctx context.Context, machine *ChangeMachine
if machine.Description != nil && *machine.Description != existingMachine.Description {
machineChanges = append(machineChanges, user.ChangeDescription(*machine.Description))
}
if machine.AccessTokenType != nil && *machine.AccessTokenType != existingMachine.AccessTokenType {
machineChanges = append(machineChanges, user.ChangeAccessTokenType(*machine.AccessTokenType))
}
if len(machineChanges) > 0 {
cmds = append(cmds, user.NewMachineChangedEvent(ctx, &existingMachine.Aggregate().Aggregate, machineChanges))
}
+54
View File
@@ -284,6 +284,60 @@ func TestCommandSide_ChangeUserMachine(t *testing.T) {
},
},
},
{
name: "change machine accessTokenType, ok",
fields: fields{
eventstore: expectEventstore(
expectFilter(
eventFromEventPusher(userAddedEvent),
),
expectPush(
user.NewMachineChangedEvent(context.Background(),
&userAgg.Aggregate,
[]user.MachineChanges{
user.ChangeAccessTokenType(domain.OIDCTokenTypeJWT),
},
),
),
),
checkPermission: newMockPermissionCheckAllowed(),
},
args: args{
ctx: context.Background(),
orgID: "org1",
machine: &ChangeMachine{
AccessTokenType: gu.Ptr(domain.OIDCTokenTypeJWT),
},
},
res: res{
want: &domain.ObjectDetails{
ResourceOwner: "org1",
},
},
},
{
name: "change machine accessTokenType, no change",
fields: fields{
eventstore: expectEventstore(
expectFilter(
eventFromEventPusher(userAddedEvent),
),
),
checkPermission: newMockPermissionCheckAllowed(),
},
args: args{
ctx: context.Background(),
orgID: "org1",
machine: &ChangeMachine{
AccessTokenType: gu.Ptr(domain.OIDCTokenTypeBearer),
},
},
res: res{
want: &domain.ObjectDetails{
ResourceOwner: "org1",
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {