2020-08-26 09:56:23 +02:00
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/caos/zitadel/internal/crypto"
|
2021-02-23 15:13:04 +01:00
|
|
|
es_models "github.com/caos/zitadel/internal/eventstore/v1/models"
|
2020-08-26 09:56:23 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type IDPConfig struct {
|
|
|
|
es_models.ObjectRoot
|
|
|
|
IDPConfigID string
|
|
|
|
Type IdpConfigType
|
|
|
|
Name string
|
2020-10-19 17:10:02 +02:00
|
|
|
StylingType IDPStylingType
|
2020-08-26 09:56:23 +02:00
|
|
|
State IDPConfigState
|
|
|
|
OIDCConfig *OIDCIDPConfig
|
|
|
|
}
|
|
|
|
|
|
|
|
type OIDCIDPConfig struct {
|
|
|
|
es_models.ObjectRoot
|
2020-09-18 13:26:28 +02:00
|
|
|
IDPConfigID string
|
|
|
|
ClientID string
|
|
|
|
ClientSecret *crypto.CryptoValue
|
|
|
|
ClientSecretString string
|
|
|
|
Issuer string
|
|
|
|
Scopes []string
|
|
|
|
IDPDisplayNameMapping OIDCMappingField
|
|
|
|
UsernameMapping OIDCMappingField
|
2020-08-26 09:56:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type IdpConfigType int32
|
|
|
|
|
|
|
|
const (
|
|
|
|
IDPConfigTypeOIDC IdpConfigType = iota
|
|
|
|
IDPConfigTypeSAML
|
|
|
|
)
|
|
|
|
|
|
|
|
type IDPConfigState int32
|
|
|
|
|
|
|
|
const (
|
|
|
|
IDPConfigStateActive IDPConfigState = iota
|
|
|
|
IDPConfigStateInactive
|
|
|
|
IDPConfigStateRemoved
|
|
|
|
)
|
|
|
|
|
2020-10-19 17:10:02 +02:00
|
|
|
type IDPStylingType int32
|
|
|
|
|
|
|
|
const (
|
|
|
|
IDPStylingTypeUnspecified IDPStylingType = iota
|
|
|
|
IDPStylingTypeGoogle
|
|
|
|
)
|
|
|
|
|
2020-09-18 13:26:28 +02:00
|
|
|
type OIDCMappingField int32
|
|
|
|
|
|
|
|
const (
|
|
|
|
OIDCMappingFieldUnspecified OIDCMappingField = iota
|
|
|
|
OIDCMappingFieldPreferredLoginName
|
|
|
|
OIDCMappingFieldEmail
|
|
|
|
)
|
|
|
|
|
2020-08-26 09:56:23 +02:00
|
|
|
func NewIDPConfig(iamID, idpID string) *IDPConfig {
|
|
|
|
return &IDPConfig{ObjectRoot: es_models.ObjectRoot{AggregateID: iamID}, IDPConfigID: idpID}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (idp *IDPConfig) IsValid(includeConfig bool) bool {
|
|
|
|
if idp.Name == "" || idp.AggregateID == "" {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if !includeConfig {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if idp.Type == IDPConfigTypeOIDC && !idp.OIDCConfig.IsValid(true) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (oi *OIDCIDPConfig) IsValid(withSecret bool) bool {
|
|
|
|
if withSecret {
|
|
|
|
return oi.ClientID != "" && oi.Issuer != "" && oi.ClientSecretString != ""
|
|
|
|
}
|
|
|
|
return oi.ClientID != "" && oi.Issuer != ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func (oi *OIDCIDPConfig) CryptSecret(crypt crypto.Crypto) error {
|
|
|
|
cryptedSecret, err := crypto.Crypt([]byte(oi.ClientSecretString), crypt)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
oi.ClientSecret = cryptedSecret
|
|
|
|
return nil
|
|
|
|
}
|
2020-10-19 17:10:02 +02:00
|
|
|
|
|
|
|
func (st IDPStylingType) GetCSSClass() string {
|
|
|
|
switch st {
|
|
|
|
case IDPStylingTypeGoogle:
|
|
|
|
return "google"
|
|
|
|
default:
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|