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"
|
|
|
|
|
2023-03-13 17:34:29 +01:00
|
|
|
"github.com/zitadel/logging"
|
|
|
|
|
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
|
2022-10-17 21:19:15 +02:00
|
|
|
DisableLoginWithEmail bool
|
|
|
|
DisableLoginWithPhone bool
|
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
|
|
|
|
2023-02-28 21:20:58 +01:00
|
|
|
Name string
|
|
|
|
StylingType IDPConfigStylingType // deprecated
|
|
|
|
IDPType IDPType
|
|
|
|
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 != ""
|
|
|
|
}
|
|
|
|
|
2023-03-13 17:34:29 +01:00
|
|
|
// DisplayName returns the name or a default
|
|
|
|
// to be used when always a name must be displayed (e.g. login)
|
|
|
|
func (p IDPProvider) DisplayName() string {
|
|
|
|
if p.Name != "" {
|
|
|
|
return p.Name
|
|
|
|
}
|
|
|
|
switch p.IDPType {
|
|
|
|
case IDPTypeGitHub:
|
|
|
|
return "GitHub"
|
|
|
|
case IDPTypeGitLab:
|
|
|
|
return "GitLab"
|
|
|
|
case IDPTypeGoogle:
|
|
|
|
return "Google"
|
|
|
|
case IDPTypeUnspecified,
|
|
|
|
IDPTypeOIDC,
|
|
|
|
IDPTypeJWT,
|
|
|
|
IDPTypeOAuth,
|
|
|
|
IDPTypeLDAP,
|
|
|
|
IDPTypeAzureAD,
|
|
|
|
IDPTypeGitHubEnterprise,
|
|
|
|
IDPTypeGitLabSelfHosted:
|
|
|
|
fallthrough
|
|
|
|
default:
|
|
|
|
// we should never get here, so log it
|
|
|
|
logging.Errorf("name of provider (type %d) is empty - id: %s", p.IDPType, p.IDPConfigID)
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|