zitadel/internal/repository/instance/idp_oidc_config.go

98 lines
2.4 KiB
Go
Raw Normal View History

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