zitadel/internal/repository/instance/idp_oidc_config.go

96 lines
2.3 KiB
Go
Raw Normal View History

package instance
2020-11-25 20:04:32 +01:00
import (
"context"
"github.com/zitadel/zitadel/internal/crypto"
"github.com/zitadel/zitadel/internal/domain"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/repository/idpconfig"
2020-11-25 20:04:32 +01:00
)
const (
IDPOIDCConfigAddedEventType eventstore.EventType = "iam.idp." + idpconfig.OIDCConfigAddedEventType
IDPOIDCConfigChangedEventType eventstore.EventType = "iam.idp." + idpconfig.OIDCConfigChangedEventType
2020-11-25 20:04:32 +01:00
)
type IDPOIDCConfigAddedEvent struct {
idpconfig.OIDCConfigAddedEvent
2020-11-25 20:04:32 +01:00
}
func NewIDPOIDCConfigAddedEvent(
ctx context.Context,
aggregate *eventstore.Aggregate,
2020-11-25 20:04:32 +01:00
clientID,
idpConfigID,
issuer,
authorizationEndpoint,
tokenEndpoint string,
2020-11-25 20:04:32 +01:00
clientSecret *crypto.CryptoValue,
idpDisplayNameMapping,
userNameMapping domain.OIDCMappingField,
2020-11-25 20:04:32 +01:00
scopes ...string,
) *IDPOIDCConfigAddedEvent {
return &IDPOIDCConfigAddedEvent{
OIDCConfigAddedEvent: *idpconfig.NewOIDCConfigAddedEvent(
2020-11-25 20:04:32 +01:00
eventstore.NewBaseEventForPush(
ctx,
aggregate,
2020-11-25 20:04:32 +01:00
IDPOIDCConfigAddedEventType,
),
clientID,
idpConfigID,
issuer,
authorizationEndpoint,
tokenEndpoint,
2020-11-25 20:04:32 +01:00
clientSecret,
idpDisplayNameMapping,
userNameMapping,
scopes...,
),
}
}
func IDPOIDCConfigAddedEventMapper(event eventstore.Event) (eventstore.Event, error) {
e, err := idpconfig.OIDCConfigAddedEventMapper(event)
2020-11-26 13:14:07 +01:00
if err != nil {
return nil, err
}
return &IDPOIDCConfigAddedEvent{OIDCConfigAddedEvent: *e.(*idpconfig.OIDCConfigAddedEvent)}, nil
2020-11-26 13:14:07 +01:00
}
2020-11-25 20:04:32 +01:00
type IDPOIDCConfigChangedEvent struct {
idpconfig.OIDCConfigChangedEvent
2020-11-25 20:04:32 +01:00
}
func NewIDPOIDCConfigChangedEvent(
ctx context.Context,
aggregate *eventstore.Aggregate,
idpConfigID string,
changes []idpconfig.OIDCConfigChanges,
) (*IDPOIDCConfigChangedEvent, error) {
changeEvent, err := idpconfig.NewOIDCConfigChangedEvent(
eventstore.NewBaseEventForPush(
ctx,
aggregate,
IDPOIDCConfigChangedEventType),
idpConfigID,
changes,
)
if err != nil {
return nil, err
2020-11-25 20:04:32 +01:00
}
return &IDPOIDCConfigChangedEvent{OIDCConfigChangedEvent: *changeEvent}, nil
2020-11-25 20:04:32 +01:00
}
2020-11-26 13:14:07 +01:00
func IDPOIDCConfigChangedEventMapper(event eventstore.Event) (eventstore.Event, error) {
e, err := idpconfig.OIDCConfigChangedEventMapper(event)
2020-11-26 13:14:07 +01:00
if err != nil {
return nil, err
}
return &IDPOIDCConfigChangedEvent{OIDCConfigChangedEvent: *e.(*idpconfig.OIDCConfigChangedEvent)}, nil
2020-11-26 13:14:07 +01:00
}