2021-01-04 13:52:13 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
2022-02-08 08:37:28 +00:00
|
|
|
"encoding/base64"
|
|
|
|
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/crypto"
|
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
|
|
"github.com/zitadel/zitadel/internal/repository/user"
|
2021-01-04 13:52:13 +00:00
|
|
|
)
|
|
|
|
|
2021-01-05 08:33:45 +00:00
|
|
|
func writeModelToHuman(wm *HumanWriteModel) *domain.Human {
|
2021-03-19 10:12:56 +00:00
|
|
|
human := &domain.Human{
|
2021-01-04 13:52:13 +00:00
|
|
|
ObjectRoot: writeModelToObjectRoot(wm.WriteModel),
|
2021-01-15 08:32:59 +00:00
|
|
|
Username: wm.UserName,
|
|
|
|
State: wm.UserState,
|
2021-01-05 08:33:45 +00:00
|
|
|
Profile: &domain.Profile{
|
2021-01-04 13:52:13 +00:00
|
|
|
FirstName: wm.FirstName,
|
|
|
|
LastName: wm.LastName,
|
|
|
|
NickName: wm.NickName,
|
|
|
|
DisplayName: wm.DisplayName,
|
|
|
|
PreferredLanguage: wm.PreferredLanguage,
|
2021-01-05 08:33:45 +00:00
|
|
|
Gender: wm.Gender,
|
2021-01-04 13:52:13 +00:00
|
|
|
},
|
2021-01-05 08:33:45 +00:00
|
|
|
Email: &domain.Email{
|
2021-01-04 13:52:13 +00:00
|
|
|
EmailAddress: wm.Email,
|
|
|
|
IsEmailVerified: wm.IsEmailVerified,
|
|
|
|
},
|
2021-03-19 10:12:56 +00:00
|
|
|
}
|
|
|
|
if wm.Phone != "" {
|
|
|
|
human.Phone = &domain.Phone{
|
|
|
|
PhoneNumber: wm.Phone,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if wm.Country != "" || wm.Locality != "" || wm.PostalCode != "" || wm.Region != "" || wm.StreetAddress != "" {
|
|
|
|
human.Address = &domain.Address{
|
2021-01-05 08:33:45 +00:00
|
|
|
Country: wm.Country,
|
|
|
|
Locality: wm.Locality,
|
|
|
|
PostalCode: wm.PostalCode,
|
|
|
|
Region: wm.Region,
|
|
|
|
StreetAddress: wm.StreetAddress,
|
2021-03-19 10:12:56 +00:00
|
|
|
}
|
2021-01-04 13:52:13 +00:00
|
|
|
}
|
2021-03-19 10:12:56 +00:00
|
|
|
return human
|
2021-01-04 13:52:13 +00:00
|
|
|
}
|
|
|
|
|
2021-01-06 10:12:56 +00:00
|
|
|
func writeModelToProfile(wm *HumanProfileWriteModel) *domain.Profile {
|
|
|
|
return &domain.Profile{
|
2021-01-04 13:52:13 +00:00
|
|
|
ObjectRoot: writeModelToObjectRoot(wm.WriteModel),
|
|
|
|
FirstName: wm.FirstName,
|
|
|
|
LastName: wm.LastName,
|
|
|
|
NickName: wm.NickName,
|
|
|
|
DisplayName: wm.DisplayName,
|
|
|
|
PreferredLanguage: wm.PreferredLanguage,
|
2021-01-06 10:12:56 +00:00
|
|
|
Gender: wm.Gender,
|
2021-01-04 13:52:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-06 10:12:56 +00:00
|
|
|
func writeModelToEmail(wm *HumanEmailWriteModel) *domain.Email {
|
|
|
|
return &domain.Email{
|
2021-01-04 13:52:13 +00:00
|
|
|
ObjectRoot: writeModelToObjectRoot(wm.WriteModel),
|
|
|
|
EmailAddress: wm.Email,
|
|
|
|
IsEmailVerified: wm.IsEmailVerified,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-07 15:06:45 +00:00
|
|
|
func writeModelToPhone(wm *HumanPhoneWriteModel) *domain.Phone {
|
|
|
|
return &domain.Phone{
|
|
|
|
ObjectRoot: writeModelToObjectRoot(wm.WriteModel),
|
|
|
|
PhoneNumber: wm.Phone,
|
|
|
|
IsPhoneVerified: wm.IsPhoneVerified,
|
|
|
|
}
|
|
|
|
}
|
2021-01-06 10:12:56 +00:00
|
|
|
func writeModelToAddress(wm *HumanAddressWriteModel) *domain.Address {
|
|
|
|
return &domain.Address{
|
2021-01-04 13:52:13 +00:00
|
|
|
ObjectRoot: writeModelToObjectRoot(wm.WriteModel),
|
|
|
|
Country: wm.Country,
|
|
|
|
Locality: wm.Locality,
|
|
|
|
PostalCode: wm.PostalCode,
|
|
|
|
Region: wm.Region,
|
|
|
|
StreetAddress: wm.StreetAddress,
|
|
|
|
}
|
|
|
|
}
|
2021-01-06 10:12:56 +00:00
|
|
|
|
|
|
|
func writeModelToMachine(wm *MachineWriteModel) *domain.Machine {
|
|
|
|
return &domain.Machine{
|
|
|
|
ObjectRoot: writeModelToObjectRoot(wm.WriteModel),
|
2021-03-19 10:12:56 +00:00
|
|
|
Username: wm.UserName,
|
2021-01-06 10:12:56 +00:00
|
|
|
Name: wm.Name,
|
|
|
|
Description: wm.Description,
|
2021-03-19 10:12:56 +00:00
|
|
|
State: wm.UserState,
|
2021-01-06 10:12:56 +00:00
|
|
|
}
|
|
|
|
}
|
2021-01-15 08:32:59 +00:00
|
|
|
|
2021-02-08 10:30:30 +00:00
|
|
|
func keyWriteModelToMachineKey(wm *MachineKeyWriteModel) *domain.MachineKey {
|
|
|
|
return &domain.MachineKey{
|
|
|
|
ObjectRoot: writeModelToObjectRoot(wm.WriteModel),
|
|
|
|
KeyID: wm.KeyID,
|
|
|
|
Type: wm.KeyType,
|
|
|
|
ExpirationDate: wm.ExpirationDate,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-08 08:37:28 +00:00
|
|
|
func personalTokenWriteModelToToken(wm *PersonalAccessTokenWriteModel, algorithm crypto.EncryptionAlgorithm) (*domain.Token, string, error) {
|
|
|
|
encrypted, err := algorithm.Encrypt([]byte(wm.TokenID + ":" + wm.AggregateID))
|
|
|
|
if err != nil {
|
|
|
|
return nil, "", err
|
|
|
|
}
|
|
|
|
return &domain.Token{
|
|
|
|
ObjectRoot: writeModelToObjectRoot(wm.WriteModel),
|
|
|
|
TokenID: wm.TokenID,
|
|
|
|
Expiration: wm.ExpirationDate,
|
|
|
|
}, base64.RawURLEncoding.EncodeToString(encrypted), nil
|
|
|
|
}
|
|
|
|
|
2023-08-11 15:36:18 +00:00
|
|
|
func readModelToWebAuthNTokens(readModel HumanWebAuthNTokensReadModel) []*domain.WebAuthNToken {
|
|
|
|
tokens := make([]*domain.WebAuthNToken, len(readModel.GetWebAuthNTokens()))
|
|
|
|
for i, token := range readModel.GetWebAuthNTokens() {
|
2021-01-15 08:32:59 +00:00
|
|
|
tokens[i] = writeModelToWebAuthN(token)
|
|
|
|
}
|
|
|
|
return tokens
|
|
|
|
}
|
|
|
|
|
|
|
|
func writeModelToWebAuthN(wm *HumanWebAuthNWriteModel) *domain.WebAuthNToken {
|
|
|
|
return &domain.WebAuthNToken{
|
|
|
|
ObjectRoot: writeModelToObjectRoot(wm.WriteModel),
|
|
|
|
WebAuthNTokenID: wm.WebauthNTokenID,
|
|
|
|
Challenge: wm.Challenge,
|
|
|
|
KeyID: wm.KeyID,
|
|
|
|
PublicKey: wm.PublicKey,
|
|
|
|
AttestationType: wm.AttestationType,
|
|
|
|
AAGUID: wm.AAGUID,
|
|
|
|
SignCount: wm.SignCount,
|
|
|
|
WebAuthNTokenName: wm.WebAuthNTokenName,
|
|
|
|
State: wm.State,
|
2023-06-27 12:36:07 +00:00
|
|
|
RPID: wm.RPID,
|
2021-01-15 08:32:59 +00:00
|
|
|
}
|
|
|
|
}
|
2021-02-08 10:30:30 +00:00
|
|
|
|
|
|
|
func authRequestDomainToAuthRequestInfo(authRequest *domain.AuthRequest) *user.AuthRequestInfo {
|
|
|
|
info := &user.AuthRequestInfo{
|
|
|
|
ID: authRequest.ID,
|
|
|
|
UserAgentID: authRequest.AgentID,
|
|
|
|
SelectedIDPConfigID: authRequest.SelectedIDPConfigID,
|
|
|
|
}
|
|
|
|
if authRequest.BrowserInfo != nil {
|
|
|
|
info.BrowserInfo = &user.BrowserInfo{
|
|
|
|
UserAgent: authRequest.BrowserInfo.UserAgent,
|
|
|
|
AcceptLanguage: authRequest.BrowserInfo.AcceptLanguage,
|
|
|
|
RemoteIP: authRequest.BrowserInfo.RemoteIP,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return info
|
|
|
|
}
|
2021-08-02 13:24:58 +00:00
|
|
|
|
|
|
|
func writeModelToPasswordlessInitCode(initCodeModel *HumanPasswordlessInitCodeWriteModel, code string) *domain.PasswordlessInitCode {
|
|
|
|
return &domain.PasswordlessInitCode{
|
|
|
|
ObjectRoot: writeModelToObjectRoot(initCodeModel.WriteModel),
|
|
|
|
CodeID: initCodeModel.CodeID,
|
|
|
|
Code: code,
|
|
|
|
Expiration: initCodeModel.Expiration,
|
|
|
|
State: initCodeModel.State,
|
|
|
|
}
|
|
|
|
}
|
2021-08-09 06:01:20 +00:00
|
|
|
|
|
|
|
func writeModelToUserMetadata(wm *UserMetadataWriteModel) *domain.Metadata {
|
|
|
|
return &domain.Metadata{
|
|
|
|
ObjectRoot: writeModelToObjectRoot(wm.WriteModel),
|
|
|
|
Key: wm.Key,
|
|
|
|
Value: wm.Value,
|
|
|
|
State: wm.State,
|
|
|
|
}
|
|
|
|
}
|