Skip to content

Commit 2e05232

Browse files
feat(auth): update password authentication handling to use new AuthenticationSettings structure
1 parent 7998c80 commit 2e05232

File tree

14 files changed

+3417
-3388
lines changed

14 files changed

+3417
-3388
lines changed

api-description/apidocs.swagger.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7020,7 +7020,7 @@ definitions:
70207020
- ORGANIZATION_OWNER_EMAIL_CHANGED
70217021
- ORGANIZATION_UPDATED
70227022
- DEMO_ORGANIZATION_CREATED
7023-
- ORGANIZATION_PASSWORD_AUTHENTICATION_CHANGED
7023+
- ORGANIZATION_AUTHENTICATION_SETTINGS_UPDATED
70247024
- FLAG_TRIGGER_CREATED
70257025
- FLAG_TRIGGER_RESET
70267026
- FLAG_TRIGGER_DESCRIPTION_CHANGED

api-description/web-api.swagger.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11094,7 +11094,7 @@ definitions:
1109411094
- ORGANIZATION_OWNER_EMAIL_CHANGED
1109511095
- ORGANIZATION_UPDATED
1109611096
- DEMO_ORGANIZATION_CREATED
11097-
- ORGANIZATION_PASSWORD_AUTHENTICATION_CHANGED
11097+
- ORGANIZATION_AUTHENTICATION_SETTINGS_UPDATED
1109811098
- FLAG_TRIGGER_CREATED
1109911099
- FLAG_TRIGGER_RESET
1110011100
- FLAG_TRIGGER_DESCRIPTION_CHANGED
@@ -11314,8 +11314,8 @@ definitions:
1131411314
type: boolean
1131511315
ownerEmail:
1131611316
type: string
11317-
passwordAuthenticationEnabled:
11318-
type: boolean
11317+
authenticationSettings:
11318+
$ref: '#/definitions/environmentAuthenticationSettings'
1131911319
required:
1132011320
- name
1132111321
- urlCode
@@ -11727,8 +11727,8 @@ definitions:
1172711727
type: string
1172811728
ownerEmail:
1172911729
type: string
11730-
passwordAuthenticationEnabled:
11731-
type: boolean
11730+
authenticationSettings:
11731+
$ref: '#/definitions/environmentAuthenticationSettings'
1173211732
environmentUpdateOrganizationResponse:
1173311733
type: object
1173411734
environmentUpdateProjectRequest:

pkg/domainevent/domain/message.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1380,7 +1380,7 @@ func LocalizedMessage(eventType proto.Event_Type, localizer locale.Localizer) *p
13801380
localizer.MustLocalizeWithTemplate(locale.Organization),
13811381
),
13821382
}
1383-
case proto.Event_ORGANIZATION_PASSWORD_AUTHENTICATION_CHANGED:
1383+
case proto.Event_ORGANIZATION_AUTHENTICATION_SETTINGS_UPDATED:
13841384
return &proto.LocalizedMessage{
13851385
Locale: localizer.GetLocale(),
13861386
Message: localizer.MustLocalizeWithTemplate(

pkg/environment/api/organization.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,13 @@ func (s *EnvironmentService) CreateDemoOrganization(
238238
return nil, err
239239
}
240240

241+
// Demo organizations need both Google and Password authentication enabled
242+
authSettings := &environmentproto.AuthenticationSettings{
243+
EnabledTypes: []environmentproto.AuthenticationType{
244+
environmentproto.AuthenticationType_AUTHENTICATION_TYPE_GOOGLE,
245+
environmentproto.AuthenticationType_AUTHENTICATION_TYPE_PASSWORD,
246+
},
247+
}
241248
organization, err := s.createOrganizationMySQL(
242249
ctx,
243250
req.Name,
@@ -246,7 +253,7 @@ func (s *EnvironmentService) CreateDemoOrganization(
246253
req.Description,
247254
false,
248255
false,
249-
true, // Enable password auth for demo organizations
256+
authSettings,
250257
localizer,
251258
)
252259
if err != nil {
@@ -391,14 +398,20 @@ func (s *EnvironmentService) CreateOrganization(
391398
}
392399
name := strings.TrimSpace(req.Command.Name)
393400
urlCode := strings.TrimSpace(req.Command.UrlCode)
401+
// Default authentication settings: Google only
402+
defaultAuthSettings := &environmentproto.AuthenticationSettings{
403+
EnabledTypes: []environmentproto.AuthenticationType{
404+
environmentproto.AuthenticationType_AUTHENTICATION_TYPE_GOOGLE,
405+
},
406+
}
394407
organization, err := domain.NewOrganization(
395408
name,
396409
urlCode,
397410
req.Command.OwnerEmail,
398411
req.Command.Description,
399412
req.Command.IsTrial,
400413
req.Command.IsSystemAdmin,
401-
true, // Default password auth enabled for backward compatibility
414+
defaultAuthSettings,
402415
)
403416
if err != nil {
404417
s.logger.Error(
@@ -496,7 +509,7 @@ func (s *EnvironmentService) createOrganizationNoCommand(
496509
req.Description,
497510
req.IsTrial,
498511
req.IsSystemAdmin,
499-
req.PasswordAuthenticationEnabled,
512+
req.AuthenticationSettings,
500513
localizer,
501514
)
502515
if err != nil {
@@ -542,7 +555,7 @@ func (s *EnvironmentService) createOrganizationMySQL(
542555
description string,
543556
isTrial bool,
544557
isSystemAdmin bool,
545-
passwordAuthenticationEnabled bool,
558+
authenticationSettings *environmentproto.AuthenticationSettings,
546559
localizer locale.Localizer,
547560
) (*domain.Organization, error) {
548561
organization, err := domain.NewOrganization(
@@ -552,7 +565,7 @@ func (s *EnvironmentService) createOrganizationMySQL(
552565
description,
553566
isTrial,
554567
isSystemAdmin,
555-
passwordAuthenticationEnabled,
568+
authenticationSettings,
556569
)
557570
if err != nil {
558571
s.logger.Error(
@@ -881,25 +894,12 @@ func (s *EnvironmentService) updateOrganizationNoCommand(
881894
return err
882895
}
883896
prevOwnerEmail = organization.OwnerEmail
884-
// Convert boolean password auth to authentication settings
885-
var authSettings *environmentproto.AuthenticationSettings
886-
if req.PasswordAuthenticationEnabled != nil {
887-
// Start with Google authentication always enabled
888-
authTypes := []environmentproto.AuthenticationType{environmentproto.AuthenticationType_AUTHENTICATION_TYPE_GOOGLE}
889-
// Add password auth if enabled
890-
if req.PasswordAuthenticationEnabled.Value {
891-
authTypes = append(authTypes, environmentproto.AuthenticationType_AUTHENTICATION_TYPE_PASSWORD)
892-
}
893-
authSettings = &environmentproto.AuthenticationSettings{
894-
EnabledTypes: authTypes,
895-
}
896-
}
897897

898898
updated, err := organization.Update(
899899
req.Name,
900900
req.Description,
901901
req.OwnerEmail,
902-
authSettings,
902+
req.AuthenticationSettings,
903903
)
904904
if err != nil {
905905
return err

pkg/environment/api/project.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,14 +561,20 @@ func (s *EnvironmentService) CreateTrialProject(
561561
}
562562
// TODO: Temporary implementations that create Organization at the same time as Project.
563563
// This should be removed when the Organization management page is added.
564+
// Default authentication settings: Google only
565+
defaultAuthSettings := &environmentproto.AuthenticationSettings{
566+
EnabledTypes: []environmentproto.AuthenticationType{
567+
environmentproto.AuthenticationType_AUTHENTICATION_TYPE_GOOGLE,
568+
},
569+
}
564570
organization, err := domain.NewOrganization(
565571
name,
566572
urlCode,
567573
req.Command.OwnerEmail,
568574
"",
569575
true,
570576
false,
571-
true, // Default password auth enabled
577+
defaultAuthSettings,
572578
)
573579
if err != nil {
574580
s.logger.Error(

pkg/environment/command/organization.go

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ func (h *organizationCommandHandler) Handle(ctx context.Context, cmd Command) er
7272
return h.convertTrial(ctx, c)
7373
case *proto.ChangeOwnerEmailOrganizationCommand:
7474
return h.changeOwnerEmail(ctx, c)
75-
case *proto.ChangePasswordAuthenticationOrganizationCommand:
76-
return h.changePasswordAuthentication(ctx, c)
75+
case *proto.UpdateAuthenticationSettingsOrganizationCommand:
76+
return h.updateAuthenticationSettings(ctx, c)
7777
default:
7878
return errUnknownCommand
7979
}
@@ -91,22 +91,15 @@ func (h *organizationCommandHandler) changeOwnerEmail(
9191
})
9292
}
9393

94-
func (h *organizationCommandHandler) changePasswordAuthentication(
94+
func (h *organizationCommandHandler) updateAuthenticationSettings(
9595
ctx context.Context,
96-
cmd *proto.ChangePasswordAuthenticationOrganizationCommand,
96+
cmd *proto.UpdateAuthenticationSettingsOrganizationCommand,
9797
) error {
98-
if cmd.PasswordAuthenticationEnabled {
99-
h.organization.EnableAuthenticationType(proto.AuthenticationType_AUTHENTICATION_TYPE_PASSWORD)
100-
} else {
101-
err := h.organization.DisableAuthenticationType(proto.AuthenticationType_AUTHENTICATION_TYPE_PASSWORD)
102-
if err != nil {
103-
return err
104-
}
105-
}
106-
return h.send(ctx, eventproto.Event_ORGANIZATION_PASSWORD_AUTHENTICATION_CHANGED,
107-
&eventproto.OrganizationPasswordAuthenticationChangedEvent{
108-
Id: h.organization.Id,
109-
PasswordAuthenticationEnabled: cmd.PasswordAuthenticationEnabled,
98+
h.organization.UpdateAuthenticationSettings(cmd.AuthenticationSettings)
99+
return h.send(ctx, eventproto.Event_ORGANIZATION_AUTHENTICATION_SETTINGS_UPDATED,
100+
&eventproto.OrganizationAuthenticationSettingsUpdatedEvent{
101+
Id: h.organization.Id,
102+
AuthenticationSettings: cmd.AuthenticationSettings,
110103
})
111104
}
112105

pkg/environment/domain/organization.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,35 +46,35 @@ var (
4646

4747
func NewOrganization(
4848
name, urlCode, ownerEmail, description string,
49-
trial, systemAdmin, passwordAuthenticationEnabled bool,
49+
trial, systemAdmin bool,
50+
authenticationSettings *proto.AuthenticationSettings,
5051
) (*Organization, error) {
5152
now := time.Now().Unix()
5253
uid, err := uuid.NewUUID()
5354
if err != nil {
5455
return nil, err
5556
}
5657

57-
// Set default authentication settings: Google is always enabled, Password based on parameter
58-
authTypes := []proto.AuthenticationType{proto.AuthenticationType_AUTHENTICATION_TYPE_GOOGLE}
59-
if passwordAuthenticationEnabled {
60-
authTypes = append(authTypes, proto.AuthenticationType_AUTHENTICATION_TYPE_PASSWORD)
58+
// Set default authentication settings if not provided: Google is always enabled
59+
if authenticationSettings == nil {
60+
authenticationSettings = &proto.AuthenticationSettings{
61+
EnabledTypes: []proto.AuthenticationType{proto.AuthenticationType_AUTHENTICATION_TYPE_GOOGLE},
62+
}
6163
}
6264

6365
return &Organization{&proto.Organization{
64-
Id: uid.String(),
65-
Name: name,
66-
UrlCode: urlCode,
67-
OwnerEmail: ownerEmail,
68-
Description: description,
69-
Disabled: false,
70-
Archived: false,
71-
Trial: trial,
72-
SystemAdmin: systemAdmin,
73-
AuthenticationSettings: &proto.AuthenticationSettings{
74-
EnabledTypes: authTypes,
75-
},
76-
CreatedAt: now,
77-
UpdatedAt: now,
66+
Id: uid.String(),
67+
Name: name,
68+
UrlCode: urlCode,
69+
OwnerEmail: ownerEmail,
70+
Description: description,
71+
Disabled: false,
72+
Archived: false,
73+
Trial: trial,
74+
SystemAdmin: systemAdmin,
75+
AuthenticationSettings: authenticationSettings,
76+
CreatedAt: now,
77+
UpdatedAt: now,
7878
}}, nil
7979
}
8080

0 commit comments

Comments
 (0)