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