diff --git a/cmd/api/src/api/v2/auth/auth.go b/cmd/api/src/api/v2/auth/auth.go index 34db75f867..e6a7c680bc 100644 --- a/cmd/api/src/api/v2/auth/auth.go +++ b/cmd/api/src/api/v2/auth/auth.go @@ -528,7 +528,7 @@ func (s ManagementResource) UpdateUser(response http.ResponseWriter, request *ht updateUserRequest v2.UpdateUserRequest pathVars = mux.Vars(request) rawUserID = pathVars[api.URIPathVariableUserID] - context = *ctx.FromRequest(request) + authCtx = *ctx.FromRequest(request) ) if userID, err := uuid.FromString(rawUserID); err != nil { @@ -550,7 +550,7 @@ func (s ManagementResource) UpdateUser(response http.ResponseWriter, request *ht user.IsDisabled = updateUserRequest.IsDisabled if user.IsDisabled { - if loggedInUser, _ := auth.GetUserFromAuthCtx(context.AuthCtx); user.ID == loggedInUser.ID { + if loggedInUser, _ := auth.GetUserFromAuthCtx(authCtx.AuthCtx); user.ID == loggedInUser.ID { api.WriteErrorResponse(request.Context(), api.BuildErrorResponse(http.StatusBadRequest, api.ErrorResponseUserSelfDisable, request), response) return } else if userSessions, err := s.db.LookupActiveSessionsByUser(request.Context(), user); err != nil { @@ -576,6 +576,7 @@ func (s ManagementResource) UpdateUser(response http.ResponseWriter, request *ht return } else { // Ensure that the AuthSecret reference is nil and that the SAML provider is set + user.AuthSecret = nil // Required or the below updateUser will re-add the authSecret user.SAMLProviderID = null.Int32From(samlProviderID) user.SSOProviderID = provider.SSOProviderID } @@ -587,6 +588,7 @@ func (s ManagementResource) UpdateUser(response http.ResponseWriter, request *ht api.HandleDatabaseError(request, response, err) return } else { + user.AuthSecret = nil // Required or the below updateUser will re-add the authSecret user.SSOProviderID = updateUserRequest.SSOProviderID if ssoProvider.Type == model.SessionAuthProviderSAML { if ssoProvider.SAMLProvider != nil { @@ -600,6 +602,7 @@ func (s ManagementResource) UpdateUser(response http.ResponseWriter, request *ht } else { // Default SAMLProviderID and SSOProviderID to null if the update request contains no SAMLProviderID and SSOProviderID user.SAMLProvider = nil + user.SSOProvider = nil user.SAMLProviderID = null.NewInt32(0, false) user.SSOProviderID = null.NewInt32(0, false) }