zitadel/internal/repository/iam/idp_oidc_config.go

98 lines
2.3 KiB
Go
Raw Normal View History

2020-11-25 19:04:32 +00:00
package iam
import (
"context"
"github.com/caos/zitadel/internal/eventstore"
2020-11-25 19:04:32 +00:00
"github.com/caos/zitadel/internal/crypto"
"github.com/caos/zitadel/internal/domain"
"github.com/caos/zitadel/internal/eventstore/repository"
"github.com/caos/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
}