2021-01-06 10:47:55 +01:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-01-03 09:19:07 +01:00
|
|
|
|
2021-01-12 12:59:51 +01:00
|
|
|
"github.com/caos/logging"
|
2021-02-23 15:13:04 +01:00
|
|
|
"github.com/caos/zitadel/internal/eventstore"
|
2021-01-12 12:59:51 +01:00
|
|
|
|
2021-02-23 15:13:04 +01:00
|
|
|
"github.com/caos/zitadel/internal/domain"
|
2021-01-06 10:47:55 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type Step7 struct {
|
|
|
|
OTP bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Step7) Step() domain.Step {
|
|
|
|
return domain.Step7
|
|
|
|
}
|
|
|
|
|
2021-02-24 11:17:39 +01:00
|
|
|
func (s *Step7) execute(ctx context.Context, commandSide *Commands) error {
|
2021-01-06 10:47:55 +01:00
|
|
|
return commandSide.SetupStep7(ctx, s)
|
|
|
|
}
|
|
|
|
|
2021-02-24 11:17:39 +01:00
|
|
|
func (c *Commands) SetupStep7(ctx context.Context, step *Step7) error {
|
2022-01-03 09:19:07 +01:00
|
|
|
fn := func(iam *IAMWriteModel) ([]eventstore.Command, error) {
|
2021-03-19 11:12:56 +01:00
|
|
|
secondFactorModel := NewIAMSecondFactorWriteModel(domain.SecondFactorTypeOTP)
|
2021-01-06 10:47:55 +01:00
|
|
|
iamAgg := IAMAggregateFromWriteModel(&secondFactorModel.SecondFactorWriteModel.WriteModel)
|
|
|
|
if !step.OTP {
|
2022-01-03 09:19:07 +01:00
|
|
|
return []eventstore.Command{}, nil
|
2021-01-06 10:47:55 +01:00
|
|
|
}
|
2021-02-24 11:17:39 +01:00
|
|
|
event, err := c.addSecondFactorToDefaultLoginPolicy(ctx, iamAgg, secondFactorModel, domain.SecondFactorTypeOTP)
|
2021-01-06 10:47:55 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-01-12 12:59:51 +01:00
|
|
|
logging.Log("SETUP-Dggsg").Info("added OTP to 2FA login policy")
|
2022-01-03 09:19:07 +01:00
|
|
|
return []eventstore.Command{event}, nil
|
2021-01-06 10:47:55 +01:00
|
|
|
}
|
2021-02-24 11:17:39 +01:00
|
|
|
return c.setup(ctx, step, fn)
|
2021-01-06 10:47:55 +01:00
|
|
|
}
|