fix: correct conditions for user update after actions in post authent… (#5535)

Correct conditions on when the user gets updated through actions in post-authentication, with an added boolean for checking if anything changed in the actions.
This commit is contained in:
Stefan Benz
2023-03-28 14:53:21 +02:00
committed by GitHub
parent 25c3c17986
commit 12a7c4b994
4 changed files with 24 additions and 14 deletions

View File

@@ -23,7 +23,7 @@ func (l *Login) runPostExternalAuthenticationActions(
httpRequest *http.Request,
idpUser idp.User,
authenticationError error,
) (*domain.ExternalUser, error) {
) (_ *domain.ExternalUser, userChanged bool, err error) {
ctx := httpRequest.Context()
resourceOwner := authRequest.RequestedOrgID
@@ -32,40 +32,50 @@ func (l *Login) runPostExternalAuthenticationActions(
}
triggerActions, err := l.query.GetActiveActionsByFlowAndTriggerType(ctx, domain.FlowTypeExternalAuthentication, domain.TriggerTypePostAuthentication, resourceOwner, false)
if err != nil {
return nil, err
return nil, false, err
}
metadataList := object.MetadataListFromDomain(user.Metadatas)
apiFields := actions.WithAPIFields(
actions.SetFields("setFirstName", func(firstName string) {
user.FirstName = firstName
userChanged = true
}),
actions.SetFields("setLastName", func(lastName string) {
user.LastName = lastName
userChanged = true
}),
actions.SetFields("setNickName", func(nickName string) {
user.NickName = nickName
userChanged = true
}),
actions.SetFields("setDisplayName", func(displayName string) {
user.DisplayName = displayName
userChanged = true
}),
actions.SetFields("setPreferredLanguage", func(preferredLanguage string) {
user.PreferredLanguage = language.Make(preferredLanguage)
userChanged = true
}),
actions.SetFields("setPreferredUsername", func(username string) {
user.PreferredUsername = username
userChanged = true
}),
actions.SetFields("setEmail", func(email domain.EmailAddress) {
user.Email = email
userChanged = true
}),
actions.SetFields("setEmailVerified", func(verified bool) {
user.IsEmailVerified = verified
userChanged = true
}),
actions.SetFields("setPhone", func(phone domain.PhoneNumber) {
user.Phone = phone
userChanged = true
}),
actions.SetFields("setPhoneVerified", func(verified bool) {
user.IsPhoneVerified = verified
userChanged = true
}),
actions.SetFields("metadata", func(c *actions.FieldConfig) interface{} {
return metadataList.MetadataListFromDomain(c.Runtime)
@@ -111,11 +121,11 @@ func (l *Login) runPostExternalAuthenticationActions(
)
cancel()
if err != nil {
return nil, err
return nil, false, err
}
}
user.Metadatas = object.MetadataListToDomain(metadataList)
return user, err
return user, userChanged, err
}
type authMethod string