2021-01-04 14:52:13 +01:00
|
|
|
package domain
|
|
|
|
|
2022-02-21 16:05:02 +01:00
|
|
|
import (
|
2022-05-16 15:39:09 +02:00
|
|
|
"net/url"
|
2022-02-21 16:05:02 +01:00
|
|
|
"time"
|
|
|
|
|
2022-04-27 01:01:45 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
2022-02-21 16:05:02 +01:00
|
|
|
)
|
2021-01-05 09:33:45 +01:00
|
|
|
|
|
|
|
type LoginPolicy struct {
|
|
|
|
models.ObjectRoot
|
|
|
|
|
2022-02-21 16:05:02 +01:00
|
|
|
Default bool
|
|
|
|
AllowUsernamePassword bool
|
|
|
|
AllowRegister bool
|
|
|
|
AllowExternalIDP bool
|
|
|
|
IDPProviders []*IDPProvider
|
|
|
|
ForceMFA bool
|
|
|
|
SecondFactors []SecondFactorType
|
|
|
|
MultiFactors []MultiFactorType
|
|
|
|
PasswordlessType PasswordlessType
|
|
|
|
HidePasswordReset bool
|
2022-05-16 15:39:09 +02:00
|
|
|
IgnoreUnknownUsernames bool
|
2022-10-06 13:30:14 +02:00
|
|
|
AllowDomainDiscovery bool
|
2022-05-16 15:39:09 +02:00
|
|
|
DefaultRedirectURI string
|
2022-02-21 16:05:02 +01:00
|
|
|
PasswordCheckLifetime time.Duration
|
|
|
|
ExternalLoginCheckLifetime time.Duration
|
|
|
|
MFAInitSkipLifetime time.Duration
|
|
|
|
SecondFactorCheckLifetime time.Duration
|
|
|
|
MultiFactorCheckLifetime time.Duration
|
2021-01-05 09:33:45 +01:00
|
|
|
}
|
|
|
|
|
2022-05-16 15:39:09 +02:00
|
|
|
func ValidateDefaultRedirectURI(rawURL string) bool {
|
|
|
|
if rawURL == "" {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
parsedURL, err := url.Parse(rawURL)
|
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
switch parsedURL.Scheme {
|
|
|
|
case "":
|
|
|
|
return false
|
|
|
|
case "http", "https":
|
|
|
|
return parsedURL.Host != ""
|
|
|
|
default:
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-05 09:33:45 +01:00
|
|
|
type IDPProvider struct {
|
|
|
|
models.ObjectRoot
|
|
|
|
Type IdentityProviderType
|
|
|
|
IDPConfigID string
|
2021-02-08 11:30:30 +01:00
|
|
|
|
|
|
|
Name string
|
|
|
|
StylingType IDPConfigStylingType
|
|
|
|
IDPConfigType IDPConfigType
|
|
|
|
IDPState IDPConfigState
|
2021-01-05 09:33:45 +01:00
|
|
|
}
|
|
|
|
|
2021-03-19 11:12:56 +01:00
|
|
|
func (p IDPProvider) IsValid() bool {
|
|
|
|
return p.IDPConfigID != ""
|
|
|
|
}
|
|
|
|
|
2021-01-04 14:52:13 +01:00
|
|
|
type PasswordlessType int32
|
|
|
|
|
|
|
|
const (
|
|
|
|
PasswordlessTypeNotAllowed PasswordlessType = iota
|
|
|
|
PasswordlessTypeAllowed
|
|
|
|
|
|
|
|
passwordlessCount
|
|
|
|
)
|
|
|
|
|
|
|
|
func (f PasswordlessType) Valid() bool {
|
|
|
|
return f >= 0 && f < passwordlessCount
|
|
|
|
}
|
2021-02-08 11:30:30 +01:00
|
|
|
|
|
|
|
func (p *LoginPolicy) HasSecondFactors() bool {
|
|
|
|
return len(p.SecondFactors) > 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *LoginPolicy) HasMultiFactors() bool {
|
|
|
|
return len(p.MultiFactors) > 0
|
|
|
|
}
|