2025-07-18 11:02:50 +01:00
|
|
|
package domain
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/zitadel/zitadel/backend/v3/storage/database"
|
2025-07-25 12:14:28 +01:00
|
|
|
"github.com/zitadel/zitadel/internal/crypto"
|
2025-07-18 11:02:50 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
//go:generate enumer -type IDPType -transform lower -trimprefix IDPType
|
|
|
|
type IDPType uint8
|
|
|
|
|
|
|
|
const (
|
2025-07-25 12:14:28 +01:00
|
|
|
IDPTypeUnspecified IDPType = iota
|
|
|
|
IDPTypeOIDC
|
|
|
|
IDPTypeJWT
|
|
|
|
IDPTypeOAuth
|
2025-07-18 11:02:50 +01:00
|
|
|
IDPTypeLDAP
|
2025-07-30 12:15:56 +01:00
|
|
|
IDPTypeAzure
|
2025-07-31 13:32:02 +01:00
|
|
|
IDPTypeGithub
|
2025-07-31 15:36:52 +01:00
|
|
|
IDPTypeGithubEnterprise
|
|
|
|
IDPTypeGitlab
|
|
|
|
IDPTypeGitlabSelfHosted
|
2025-07-18 11:02:50 +01:00
|
|
|
IDPTypeGoogle
|
|
|
|
IDPTypeApple
|
2025-07-25 12:14:28 +01:00
|
|
|
IDPTypeSAML
|
2025-07-18 11:02:50 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
//go:generate enumer -type IDPState -transform lower -trimprefix IDPState
|
|
|
|
type IDPState uint8
|
|
|
|
|
|
|
|
const (
|
|
|
|
IDPStateActive IDPState = iota
|
|
|
|
IDPStateInactive
|
|
|
|
)
|
|
|
|
|
2025-07-29 13:24:42 +01:00
|
|
|
//go:generate enumer -type IDPAutoLinkingOption -transform lower -trimprefix IDPAutoLinkingOption
|
|
|
|
type IDPAutoLinkingOption uint8
|
|
|
|
|
|
|
|
const (
|
|
|
|
IDPAutoLinkingOptionUnspecified IDPAutoLinkingOption = iota
|
|
|
|
IDPAutoLinkingOptionUserName
|
|
|
|
IDPAutoLinkingOptionEmail
|
|
|
|
)
|
|
|
|
|
2025-07-25 12:14:28 +01:00
|
|
|
type OIDCMappingField int8
|
|
|
|
|
|
|
|
const (
|
|
|
|
OIDCMappingFieldUnspecified OIDCMappingField = iota
|
|
|
|
OIDCMappingFieldPreferredLoginName
|
|
|
|
OIDCMappingFieldEmail
|
|
|
|
// count is for validation purposes
|
|
|
|
oidcMappingFieldCount
|
|
|
|
)
|
|
|
|
|
2025-07-18 11:02:50 +01:00
|
|
|
type IdentityProvider struct {
|
|
|
|
InstanceID string `json:"instanceId,omitempty" db:"instance_id"`
|
2025-07-22 16:06:22 +01:00
|
|
|
OrgID *string `json:"orgId,omitempty" db:"org_id"`
|
2025-07-18 11:02:50 +01:00
|
|
|
ID string `json:"id,omitempty" db:"id"`
|
|
|
|
State string `json:"state,omitempty" db:"state"`
|
|
|
|
Name string `json:"name,omitempty" db:"name"`
|
|
|
|
Type string `json:"type,omitempty" db:"type"`
|
2025-07-18 15:55:18 +01:00
|
|
|
AllowCreation bool `json:"allowCreation,omitempty" db:"allow_creation"`
|
2025-07-25 17:06:18 +01:00
|
|
|
AutoRegister bool `json:"autoRegister,omitempty" db:"auto_register"`
|
2025-07-18 15:55:18 +01:00
|
|
|
AllowAutoCreation bool `json:"allowAutoCreation,omitempty" db:"allow_auto_creation"`
|
|
|
|
AllowAutoUpdate bool `json:"allowAutoUpdate,omitempty" db:"allow_auto_update"`
|
|
|
|
AllowLinking bool `json:"allowLinking,omitempty" db:"allow_linking"`
|
2025-07-29 13:24:42 +01:00
|
|
|
AllowAutoLinking string `json:"allowAutoLinking,omitempty" db:"allow_auto_linking"`
|
|
|
|
StylingType *int16 `json:"stylingType,omitempty" db:"styling_type"`
|
2025-07-22 16:06:22 +01:00
|
|
|
Payload *string `json:"payload,omitempty" db:"payload"`
|
2025-07-18 11:02:50 +01:00
|
|
|
CreatedAt time.Time `json:"createdAt,omitempty" db:"created_at"`
|
|
|
|
UpdatedAt time.Time `json:"updatedAt,omitempty" db:"updated_at"`
|
|
|
|
}
|
|
|
|
|
2025-07-25 12:14:28 +01:00
|
|
|
type OIDC struct {
|
|
|
|
IDPConfigID string `json:"idpConfigId"`
|
|
|
|
ClientID string `json:"clientId,omitempty"`
|
|
|
|
ClientSecret crypto.CryptoValue `json:"clientSecret,omitempty"`
|
|
|
|
Issuer string `json:"issuer,omitempty"`
|
|
|
|
AuthorizationEndpoint string `json:"authorizationEndpoint,omitempty"`
|
|
|
|
TokenEndpoint string `json:"tokenEndpoint,omitempty"`
|
|
|
|
Scopes []string `json:"scopes,omitempty"`
|
|
|
|
IDPDisplayNameMapping OIDCMappingField `json:"IDPDisplayNameMapping,omitempty"`
|
|
|
|
UserNameMapping OIDCMappingField `json:"usernameMapping,omitempty"`
|
2025-07-29 13:24:42 +01:00
|
|
|
IsIDTokenMapping bool `json:"idTokenMapping,omitempty"`
|
|
|
|
UsePKCE bool `json:"usePKCE,omitempty"`
|
2025-07-25 12:14:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type IDPOIDC struct {
|
|
|
|
*IdentityProvider
|
|
|
|
OIDC
|
|
|
|
}
|
|
|
|
|
|
|
|
type JWT struct {
|
|
|
|
JWTEndpoint string `json:"jwtEndpoint,omitempty"`
|
|
|
|
Issuer string `json:"issuer,omitempty"`
|
|
|
|
KeysEndpoint string `json:"keysEndpoint,omitempty"`
|
|
|
|
HeaderName string `json:"headerName,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type IDPJWT struct {
|
|
|
|
*IdentityProvider
|
|
|
|
JWT
|
|
|
|
}
|
|
|
|
|
2025-07-29 13:24:42 +01:00
|
|
|
type OAuth struct {
|
|
|
|
ClientID string `json:"clientId,omitempty"`
|
|
|
|
ClientSecret *crypto.CryptoValue `json:"clientSecret,omitempty"`
|
|
|
|
AuthorizationEndpoint string `json:"authorizationEndpoint,omitempty"`
|
|
|
|
TokenEndpoint string `json:"tokenEndpoint,omitempty"`
|
|
|
|
UserEndpoint string `json:"userEndpoint,omitempty"`
|
|
|
|
Scopes []string `json:"scopes,omitempty"`
|
|
|
|
IDAttribute string `json:"idAttribute,omitempty"`
|
|
|
|
UsePKCE bool `json:"usePKCE,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type IDPOAuth struct {
|
|
|
|
*IdentityProvider
|
|
|
|
OAuth
|
|
|
|
}
|
|
|
|
|
2025-07-30 12:15:56 +01:00
|
|
|
//go:generate enumer -type AzureTenantType -transform lower -trimprefix AzureTenantType
|
|
|
|
type AzureTenantType uint8
|
|
|
|
|
|
|
|
const (
|
|
|
|
AzureTenantTypeCommon AzureTenantType = iota
|
|
|
|
AzureTenantTypeOrganizations
|
|
|
|
AzureTenantTypeConsumers
|
|
|
|
)
|
|
|
|
|
|
|
|
type Azure struct {
|
|
|
|
ClientID string `json:"client_id,omitempty"`
|
|
|
|
ClientSecret *crypto.CryptoValue `json:"client_secret,omitempty"`
|
|
|
|
Scopes []string `json:"scopes,omitempty"`
|
|
|
|
Tenant string `json:"tenant,omitempty"`
|
|
|
|
IsEmailVerified bool `json:"isEmailVerified,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type IDPOAzureAD struct {
|
|
|
|
*IdentityProvider
|
|
|
|
Azure
|
|
|
|
}
|
|
|
|
|
|
|
|
type Google struct {
|
|
|
|
ClientID string `json:"clientId"`
|
|
|
|
ClientSecret *crypto.CryptoValue `json:"clientSecret"`
|
|
|
|
Scopes []string `json:"scopes,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type IDPGoogle struct {
|
|
|
|
*IdentityProvider
|
|
|
|
Google
|
|
|
|
}
|
|
|
|
|
2025-07-31 13:32:02 +01:00
|
|
|
type Github struct {
|
|
|
|
ClientID string `json:"clientId"`
|
|
|
|
ClientSecret *crypto.CryptoValue `json:"clientSecret"`
|
|
|
|
Scopes []string `json:"scopes,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type IDPGithub struct {
|
|
|
|
*IdentityProvider
|
|
|
|
Github
|
|
|
|
}
|
|
|
|
|
2025-07-31 15:36:52 +01:00
|
|
|
type GithubEnterprise struct {
|
|
|
|
ClientID string `json:"clientId,omitempty"`
|
|
|
|
ClientSecret *crypto.CryptoValue `json:"clientSecret,omitempty"`
|
|
|
|
AuthorizationEndpoint string `json:"authorizationEndpoint,omitempty"`
|
|
|
|
TokenEndpoint string `json:"tokenEndpoint,omitempty"`
|
|
|
|
UserEndpoint string `json:"userEndpoint,omitempty"`
|
|
|
|
Scopes []string `json:"scopes,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type IDPGithubEnterprise struct {
|
|
|
|
*IdentityProvider
|
|
|
|
GithubEnterprise
|
|
|
|
}
|
|
|
|
|
2025-07-18 15:55:18 +01:00
|
|
|
// IDPIdentifierCondition is used to help specify a single identity_provider,
|
|
|
|
// it will either be used as the identity_provider ID or identity_provider name,
|
2025-07-25 12:14:28 +01:00
|
|
|
// as identity_provider can be identified either using (instanceID + OrgID + ID) OR (instanceID + OrgID + name)
|
2025-07-18 15:55:18 +01:00
|
|
|
type IDPIdentifierCondition interface {
|
|
|
|
database.Condition
|
|
|
|
}
|
|
|
|
|
2025-07-18 11:02:50 +01:00
|
|
|
type idProviderColumns interface {
|
|
|
|
InstanceIDColumn() database.Column
|
|
|
|
OrgIDColumn() database.Column
|
|
|
|
IDColumn() database.Column
|
|
|
|
StateColumn() database.Column
|
|
|
|
NameColumn() database.Column
|
|
|
|
TypeColumn() database.Column
|
|
|
|
AllowCreationColumn() database.Column
|
2025-07-25 17:06:18 +01:00
|
|
|
AutoRegisterColumn() database.Column
|
2025-07-18 11:02:50 +01:00
|
|
|
AllowAutoCreationColumn() database.Column
|
|
|
|
AllowAutoUpdateColumn() database.Column
|
|
|
|
AllowLinkingColumn() database.Column
|
2025-07-25 17:06:18 +01:00
|
|
|
AllowAutoLinkingColumn() database.Column
|
2025-07-18 11:02:50 +01:00
|
|
|
StylingTypeColumn() database.Column
|
|
|
|
PayloadColumn() database.Column
|
|
|
|
CreatedAtColumn() database.Column
|
|
|
|
UpdatedAtColumn() database.Column
|
|
|
|
}
|
|
|
|
|
|
|
|
type idProviderConditions interface {
|
|
|
|
InstanceIDCondition(id string) database.Condition
|
2025-07-22 16:06:22 +01:00
|
|
|
OrgIDCondition(id *string) database.Condition
|
2025-07-18 15:55:18 +01:00
|
|
|
IDCondition(id string) IDPIdentifierCondition
|
2025-07-18 11:02:50 +01:00
|
|
|
StateCondition(state IDPState) database.Condition
|
2025-07-18 15:55:18 +01:00
|
|
|
NameCondition(name string) IDPIdentifierCondition
|
2025-07-18 11:02:50 +01:00
|
|
|
TypeCondition(typee IDPType) database.Condition
|
2025-07-25 17:06:18 +01:00
|
|
|
AutoRegisterCondition(allow bool) database.Condition
|
2025-07-18 11:02:50 +01:00
|
|
|
AllowCreationCondition(allow bool) database.Condition
|
|
|
|
AllowAutoCreationCondition(allow bool) database.Condition
|
|
|
|
AllowAutoUpdateCondition(allow bool) database.Condition
|
|
|
|
AllowLinkingCondition(allow bool) database.Condition
|
2025-07-29 13:24:42 +01:00
|
|
|
AllowAutoLinkingCondition(linkingType IDPAutoLinkingOption) database.Condition
|
2025-07-18 11:02:50 +01:00
|
|
|
StylingTypeCondition(style int16) database.Condition
|
|
|
|
PayloadCondition(payload string) database.Condition
|
|
|
|
}
|
|
|
|
|
|
|
|
type idProviderChanges interface {
|
|
|
|
SetName(name string) database.Change
|
|
|
|
SetState(state IDPState) database.Change
|
|
|
|
SetAllowCreation(allow bool) database.Change
|
2025-07-25 17:06:18 +01:00
|
|
|
SetAutoRegister(allow bool) database.Change
|
2025-07-18 11:02:50 +01:00
|
|
|
SetAllowAutoCreation(allow bool) database.Change
|
|
|
|
SetAllowAutoUpdate(allow bool) database.Change
|
|
|
|
SetAllowLinking(allow bool) database.Change
|
2025-07-25 17:06:18 +01:00
|
|
|
SetAutoAllowLinking(allow bool) database.Change
|
2025-07-18 11:02:50 +01:00
|
|
|
SetStylingType(stylingType int16) database.Change
|
|
|
|
SetPayload(payload string) database.Change
|
|
|
|
}
|
|
|
|
|
|
|
|
type IDProviderRepository interface {
|
|
|
|
idProviderColumns
|
|
|
|
idProviderConditions
|
|
|
|
idProviderChanges
|
|
|
|
|
2025-07-25 12:14:28 +01:00
|
|
|
Get(ctx context.Context, id IDPIdentifierCondition, instanceID string, orgID *string) (*IdentityProvider, error)
|
2025-07-18 11:02:50 +01:00
|
|
|
List(ctx context.Context, conditions ...database.Condition) ([]*IdentityProvider, error)
|
|
|
|
|
|
|
|
Create(ctx context.Context, idp *IdentityProvider) error
|
2025-07-25 12:14:28 +01:00
|
|
|
Update(ctx context.Context, id IDPIdentifierCondition, instanceID string, orgID *string, changes ...database.Change) (int64, error)
|
|
|
|
Delete(ctx context.Context, id IDPIdentifierCondition, instanceID string, orgID *string) (int64, error)
|
|
|
|
|
|
|
|
GetOIDC(ctx context.Context, id IDPIdentifierCondition, instanceID string, orgID *string) (*IDPOIDC, error)
|
|
|
|
GetJWT(ctx context.Context, id IDPIdentifierCondition, instanceID string, orgID *string) (*IDPJWT, error)
|
2025-07-29 13:24:42 +01:00
|
|
|
|
|
|
|
GetOAuth(ctx context.Context, id IDPIdentifierCondition, instanceID string, orgID *string) (*IDPOAuth, error)
|
2025-07-30 12:15:56 +01:00
|
|
|
|
|
|
|
GetOAzureAD(ctx context.Context, id IDPIdentifierCondition, instanceID string, orgID *string) (*IDPOAzureAD, error)
|
|
|
|
GetGoogle(ctx context.Context, id IDPIdentifierCondition, instanceID string, orgID *string) (*IDPGoogle, error)
|
2025-07-31 13:32:02 +01:00
|
|
|
GetGithub(ctx context.Context, id IDPIdentifierCondition, instanceID string, orgID *string) (*IDPGithub, error)
|
2025-07-31 15:36:52 +01:00
|
|
|
GetGithubEnterprise(ctx context.Context, id IDPIdentifierCondition, instanceID string, orgID *string) (*IDPGithubEnterprise, error)
|
2025-07-18 11:02:50 +01:00
|
|
|
}
|