mirror of
https://github.com/andwati/zitadel.git
synced 2026-10-18 05:52:51 +00:00
# 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]>
78 lines
2.4 KiB
Go
78 lines
2.4 KiB
Go
package user
|
|
|
|
import (
|
|
"context"
|
|
|
|
"connectrpc.com/connect"
|
|
"google.golang.org/protobuf/types/known/timestamppb"
|
|
|
|
"github.com/zitadel/zitadel/internal/command"
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
|
"github.com/zitadel/zitadel/pkg/grpc/user/v2"
|
|
)
|
|
|
|
func (s *Server) createUserTypeMachine(ctx context.Context, machinePb *user.CreateUserRequest_Machine, orgId, userName, userId string) (*connect.Response[user.CreateUserResponse], error) {
|
|
cmd := &command.Machine{
|
|
Username: userName,
|
|
Name: machinePb.Name,
|
|
Description: machinePb.GetDescription(),
|
|
AccessTokenType: accessTokenTypeToDomain(machinePb.GetAccessTokenType()),
|
|
ObjectRoot: models.ObjectRoot{
|
|
ResourceOwner: orgId,
|
|
AggregateID: userId,
|
|
},
|
|
}
|
|
details, err := s.command.AddMachine(
|
|
ctx,
|
|
cmd,
|
|
nil,
|
|
s.command.NewPermissionCheckUserWrite(ctx, true),
|
|
command.AddMachineWithUsernameToIDFallback(),
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return connect.NewResponse(&user.CreateUserResponse{
|
|
Id: cmd.AggregateID,
|
|
CreationDate: timestamppb.New(details.EventDate),
|
|
}), nil
|
|
}
|
|
|
|
func (s *Server) updateUserTypeMachine(ctx context.Context, machinePb *user.UpdateUserRequest_Machine, userId string, userName *string) (*connect.Response[user.UpdateUserResponse], error) {
|
|
cmd := updateMachineUserToCommand(userId, userName, machinePb)
|
|
err := s.command.ChangeUserMachine(ctx, cmd)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return connect.NewResponse(&user.UpdateUserResponse{
|
|
ChangeDate: timestamppb.New(cmd.Details.EventDate),
|
|
}), nil
|
|
}
|
|
|
|
func updateMachineUserToCommand(userId string, userName *string, machine *user.UpdateUserRequest_Machine) *command.ChangeMachine {
|
|
var accessTokenType *domain.OIDCTokenType
|
|
if machine.AccessTokenType != nil {
|
|
tokenType := accessTokenTypeToDomain(*machine.AccessTokenType)
|
|
accessTokenType = &tokenType
|
|
}
|
|
return &command.ChangeMachine{
|
|
ID: userId,
|
|
Username: userName,
|
|
Name: machine.Name,
|
|
Description: machine.Description,
|
|
AccessTokenType: accessTokenType,
|
|
}
|
|
}
|
|
|
|
func accessTokenTypeToDomain(accessTokenType user.AccessTokenType) domain.OIDCTokenType {
|
|
switch accessTokenType {
|
|
case user.AccessTokenType_ACCESS_TOKEN_TYPE_BEARER:
|
|
return domain.OIDCTokenTypeBearer
|
|
case user.AccessTokenType_ACCESS_TOKEN_TYPE_JWT:
|
|
return domain.OIDCTokenTypeJWT
|
|
default:
|
|
return domain.OIDCTokenTypeBearer
|
|
}
|
|
}
|