2020-05-18 12:06:36 +02:00
|
|
|
package model
|
|
|
|
|
2021-02-08 11:30:30 +01:00
|
|
|
import (
|
2021-02-23 15:13:04 +01:00
|
|
|
"github.com/caos/zitadel/internal/domain"
|
2021-02-08 11:30:30 +01:00
|
|
|
)
|
|
|
|
|
2020-05-18 12:06:36 +02:00
|
|
|
type NextStep interface {
|
|
|
|
Type() NextStepType
|
|
|
|
}
|
|
|
|
|
|
|
|
type NextStepType int32
|
|
|
|
|
|
|
|
const (
|
|
|
|
NextStepUnspecified NextStepType = iota
|
|
|
|
NextStepLogin
|
|
|
|
NextStepUserSelection
|
2020-06-05 07:50:04 +02:00
|
|
|
NextStepInitUser
|
2020-05-18 12:06:36 +02:00
|
|
|
NextStepPassword
|
|
|
|
NextStepChangePassword
|
|
|
|
NextStepInitPassword
|
|
|
|
NextStepVerifyEmail
|
2020-12-02 17:00:04 +01:00
|
|
|
NextStepMFAPrompt
|
|
|
|
NextStepMFAVerify
|
2020-05-18 12:06:36 +02:00
|
|
|
NextStepRedirectToCallback
|
2020-08-27 17:18:23 +02:00
|
|
|
NextStepChangeUsername
|
2020-09-18 13:26:28 +02:00
|
|
|
NextStepLinkUsers
|
|
|
|
NextStepExternalNotFoundOption
|
2020-10-02 08:02:09 +02:00
|
|
|
NextStepExternalLogin
|
2020-10-16 07:49:38 +02:00
|
|
|
NextStepGrantRequired
|
2020-12-02 17:00:04 +01:00
|
|
|
NextStepPasswordless
|
2020-05-18 12:06:36 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type UserSessionState int32
|
|
|
|
|
|
|
|
const (
|
|
|
|
UserSessionStateActive UserSessionState = iota
|
|
|
|
UserSessionStateTerminated
|
|
|
|
)
|
|
|
|
|
2020-06-05 07:50:04 +02:00
|
|
|
type LoginStep struct{}
|
2020-05-18 12:06:36 +02:00
|
|
|
|
|
|
|
func (s *LoginStep) Type() NextStepType {
|
|
|
|
return NextStepLogin
|
|
|
|
}
|
|
|
|
|
|
|
|
type SelectUserStep struct {
|
|
|
|
Users []UserSelection
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SelectUserStep) Type() NextStepType {
|
|
|
|
return NextStepUserSelection
|
|
|
|
}
|
|
|
|
|
|
|
|
type UserSelection struct {
|
2020-12-14 10:54:29 +01:00
|
|
|
UserID string
|
|
|
|
DisplayName string
|
2021-03-25 14:41:07 +01:00
|
|
|
UserName string
|
2020-12-14 10:54:29 +01:00
|
|
|
LoginName string
|
|
|
|
UserSessionState UserSessionState
|
|
|
|
SelectionPossible bool
|
2020-05-18 12:06:36 +02:00
|
|
|
}
|
|
|
|
|
2020-06-05 07:50:04 +02:00
|
|
|
type InitUserStep struct {
|
|
|
|
PasswordSet bool
|
|
|
|
}
|
|
|
|
|
2020-09-18 13:26:28 +02:00
|
|
|
type ExternalNotFoundOptionStep struct{}
|
|
|
|
|
|
|
|
func (s *ExternalNotFoundOptionStep) Type() NextStepType {
|
|
|
|
return NextStepExternalNotFoundOption
|
|
|
|
}
|
|
|
|
|
2020-06-05 07:50:04 +02:00
|
|
|
func (s *InitUserStep) Type() NextStepType {
|
|
|
|
return NextStepInitUser
|
2020-05-18 12:06:36 +02:00
|
|
|
}
|
|
|
|
|
2020-06-05 07:50:04 +02:00
|
|
|
type PasswordStep struct{}
|
|
|
|
|
2020-05-18 12:06:36 +02:00
|
|
|
func (s *PasswordStep) Type() NextStepType {
|
|
|
|
return NextStepPassword
|
|
|
|
}
|
|
|
|
|
2020-10-02 08:02:09 +02:00
|
|
|
type ExternalLoginStep struct {
|
|
|
|
SelectedIDPConfigID string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ExternalLoginStep) Type() NextStepType {
|
|
|
|
return NextStepExternalLogin
|
|
|
|
}
|
|
|
|
|
2020-12-02 17:00:04 +01:00
|
|
|
type PasswordlessStep struct{}
|
|
|
|
|
|
|
|
func (s *PasswordlessStep) Type() NextStepType {
|
|
|
|
return NextStepPasswordless
|
|
|
|
}
|
|
|
|
|
2020-06-05 07:50:04 +02:00
|
|
|
type ChangePasswordStep struct{}
|
2020-05-18 12:06:36 +02:00
|
|
|
|
|
|
|
func (s *ChangePasswordStep) Type() NextStepType {
|
|
|
|
return NextStepChangePassword
|
|
|
|
}
|
|
|
|
|
2020-06-05 07:50:04 +02:00
|
|
|
type InitPasswordStep struct{}
|
2020-05-18 12:06:36 +02:00
|
|
|
|
|
|
|
func (s *InitPasswordStep) Type() NextStepType {
|
|
|
|
return NextStepInitPassword
|
|
|
|
}
|
|
|
|
|
2020-08-27 17:18:23 +02:00
|
|
|
type ChangeUsernameStep struct{}
|
|
|
|
|
|
|
|
func (s *ChangeUsernameStep) Type() NextStepType {
|
|
|
|
return NextStepChangeUsername
|
|
|
|
}
|
|
|
|
|
2020-06-05 07:50:04 +02:00
|
|
|
type VerifyEMailStep struct{}
|
2020-05-18 12:06:36 +02:00
|
|
|
|
|
|
|
func (s *VerifyEMailStep) Type() NextStepType {
|
|
|
|
return NextStepVerifyEmail
|
|
|
|
}
|
|
|
|
|
2020-12-02 17:00:04 +01:00
|
|
|
type MFAPromptStep struct {
|
2020-05-18 12:06:36 +02:00
|
|
|
Required bool
|
2020-12-02 17:00:04 +01:00
|
|
|
MFAProviders []MFAType
|
2020-05-18 12:06:36 +02:00
|
|
|
}
|
|
|
|
|
2020-12-02 17:00:04 +01:00
|
|
|
func (s *MFAPromptStep) Type() NextStepType {
|
|
|
|
return NextStepMFAPrompt
|
2020-05-18 12:06:36 +02:00
|
|
|
}
|
|
|
|
|
2020-12-02 17:00:04 +01:00
|
|
|
type MFAVerificationStep struct {
|
|
|
|
MFAProviders []MFAType
|
2020-05-18 12:06:36 +02:00
|
|
|
}
|
|
|
|
|
2020-12-02 17:00:04 +01:00
|
|
|
func (s *MFAVerificationStep) Type() NextStepType {
|
|
|
|
return NextStepMFAVerify
|
2020-05-18 12:06:36 +02:00
|
|
|
}
|
|
|
|
|
2020-09-18 13:26:28 +02:00
|
|
|
type LinkUsersStep struct{}
|
|
|
|
|
|
|
|
func (s *LinkUsersStep) Type() NextStepType {
|
|
|
|
return NextStepLinkUsers
|
|
|
|
}
|
|
|
|
|
2020-10-16 07:49:38 +02:00
|
|
|
type GrantRequiredStep struct{}
|
|
|
|
|
|
|
|
func (s *GrantRequiredStep) Type() NextStepType {
|
|
|
|
return NextStepGrantRequired
|
|
|
|
}
|
|
|
|
|
2020-06-05 07:50:04 +02:00
|
|
|
type RedirectToCallbackStep struct{}
|
2020-05-18 12:06:36 +02:00
|
|
|
|
|
|
|
func (s *RedirectToCallbackStep) Type() NextStepType {
|
|
|
|
return NextStepRedirectToCallback
|
|
|
|
}
|
|
|
|
|
2020-11-04 11:26:10 +01:00
|
|
|
type MFAType int
|
2020-05-18 12:06:36 +02:00
|
|
|
|
|
|
|
const (
|
2020-11-04 11:26:10 +01:00
|
|
|
MFATypeOTP MFAType = iota
|
|
|
|
MFATypeU2F
|
2020-12-02 17:00:04 +01:00
|
|
|
MFATypeU2FUserVerification
|
2020-05-18 12:06:36 +02:00
|
|
|
)
|
|
|
|
|
2020-11-04 11:26:10 +01:00
|
|
|
type MFALevel int
|
2020-05-18 12:06:36 +02:00
|
|
|
|
|
|
|
const (
|
2020-11-04 11:26:10 +01:00
|
|
|
MFALevelNotSetUp MFALevel = iota
|
|
|
|
MFALevelSecondFactor
|
|
|
|
MFALevelMultiFactor
|
|
|
|
MFALevelMultiFactorCertified
|
2020-05-18 12:06:36 +02:00
|
|
|
)
|
2021-02-08 11:30:30 +01:00
|
|
|
|
|
|
|
func MFATypeToDomain(mfaType MFAType) domain.MFAType {
|
|
|
|
switch mfaType {
|
|
|
|
case MFATypeOTP:
|
|
|
|
return domain.MFATypeOTP
|
|
|
|
case MFATypeU2F:
|
|
|
|
return domain.MFATypeU2F
|
|
|
|
case MFATypeU2FUserVerification:
|
|
|
|
return domain.MFATypeU2FUserVerification
|
|
|
|
default:
|
|
|
|
return domain.MFATypeOTP
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func MFALevelToDomain(mfaLevel MFALevel) domain.MFALevel {
|
|
|
|
switch mfaLevel {
|
|
|
|
case MFALevelNotSetUp:
|
|
|
|
return domain.MFALevelNotSetUp
|
|
|
|
case MFALevelSecondFactor:
|
|
|
|
return domain.MFALevelSecondFactor
|
|
|
|
case MFALevelMultiFactor:
|
|
|
|
return domain.MFALevelMultiFactor
|
|
|
|
case MFALevelMultiFactorCertified:
|
|
|
|
return domain.MFALevelMultiFactorCertified
|
|
|
|
default:
|
|
|
|
return domain.MFALevelNotSetUp
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func UserSessionStateToDomain(state UserSessionState) domain.UserSessionState {
|
|
|
|
switch state {
|
|
|
|
case UserSessionStateActive:
|
|
|
|
return domain.UserSessionStateActive
|
|
|
|
case UserSessionStateTerminated:
|
|
|
|
return domain.UserSessionStateTerminated
|
|
|
|
default:
|
|
|
|
return domain.UserSessionStateActive
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|