2022-03-24 17:21:34 +01:00
|
|
|
package instance
|
2020-11-25 20:04:32 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-01-03 09:19:07 +01:00
|
|
|
|
2022-04-27 01:01:45 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/crypto"
|
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
2023-10-19 12:19:10 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
2022-04-27 01:01:45 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/repository/idpconfig"
|
2020-11-25 20:04:32 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2021-01-04 14:52:13 +01:00
|
|
|
IDPOIDCConfigAddedEventType eventstore.EventType = "iam.idp." + idpconfig.OIDCConfigAddedEventType
|
2021-09-14 15:15:01 +02:00
|
|
|
IDPOIDCConfigChangedEventType eventstore.EventType = "iam.idp." + idpconfig.OIDCConfigChangedEventType
|
2020-11-25 20:04:32 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type IDPOIDCConfigAddedEvent struct {
|
2021-01-04 14:52:13 +01:00
|
|
|
idpconfig.OIDCConfigAddedEvent
|
2020-11-25 20:04:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewIDPOIDCConfigAddedEvent(
|
|
|
|
ctx context.Context,
|
2021-02-18 14:48:27 +01:00
|
|
|
aggregate *eventstore.Aggregate,
|
2020-11-25 20:04:32 +01:00
|
|
|
clientID,
|
|
|
|
idpConfigID,
|
2021-07-06 16:39:48 +02:00
|
|
|
issuer,
|
|
|
|
authorizationEndpoint,
|
|
|
|
tokenEndpoint string,
|
2020-11-25 20:04:32 +01:00
|
|
|
clientSecret *crypto.CryptoValue,
|
|
|
|
idpDisplayNameMapping,
|
2021-01-04 14:52:13 +01:00
|
|
|
userNameMapping domain.OIDCMappingField,
|
2020-11-25 20:04:32 +01:00
|
|
|
scopes ...string,
|
|
|
|
) *IDPOIDCConfigAddedEvent {
|
|
|
|
|
|
|
|
return &IDPOIDCConfigAddedEvent{
|
2021-01-04 14:52:13 +01:00
|
|
|
OIDCConfigAddedEvent: *idpconfig.NewOIDCConfigAddedEvent(
|
2020-11-25 20:04:32 +01:00
|
|
|
eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
2021-02-18 14:48:27 +01:00
|
|
|
aggregate,
|
2020-11-25 20:04:32 +01:00
|
|
|
IDPOIDCConfigAddedEventType,
|
|
|
|
),
|
|
|
|
clientID,
|
|
|
|
idpConfigID,
|
|
|
|
issuer,
|
2021-07-06 16:39:48 +02:00
|
|
|
authorizationEndpoint,
|
|
|
|
tokenEndpoint,
|
2020-11-25 20:04:32 +01:00
|
|
|
clientSecret,
|
|
|
|
idpDisplayNameMapping,
|
|
|
|
userNameMapping,
|
|
|
|
scopes...,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
func IDPOIDCConfigAddedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2021-01-04 14:52:13 +01:00
|
|
|
e, err := idpconfig.OIDCConfigAddedEventMapper(event)
|
2020-11-26 13:14:07 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-01-04 14:52:13 +01:00
|
|
|
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 {
|
2021-01-04 14:52:13 +01:00
|
|
|
idpconfig.OIDCConfigChangedEvent
|
2020-11-25 20:04:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewIDPOIDCConfigChangedEvent(
|
|
|
|
ctx context.Context,
|
2021-02-18 14:48:27 +01:00
|
|
|
aggregate *eventstore.Aggregate,
|
2021-01-20 11:06:52 +01:00
|
|
|
idpConfigID string,
|
|
|
|
changes []idpconfig.OIDCConfigChanges,
|
|
|
|
) (*IDPOIDCConfigChangedEvent, error) {
|
|
|
|
changeEvent, err := idpconfig.NewOIDCConfigChangedEvent(
|
2021-02-18 14:48:27 +01:00
|
|
|
eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
IDPOIDCConfigChangedEventType),
|
2021-01-20 11:06:52 +01:00
|
|
|
idpConfigID,
|
|
|
|
changes,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2020-11-25 20:04:32 +01:00
|
|
|
}
|
2021-01-20 11:06:52 +01:00
|
|
|
return &IDPOIDCConfigChangedEvent{OIDCConfigChangedEvent: *changeEvent}, nil
|
2020-11-25 20:04:32 +01:00
|
|
|
}
|
2020-11-26 13:14:07 +01:00
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
func IDPOIDCConfigChangedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2021-01-04 14:52:13 +01:00
|
|
|
e, err := idpconfig.OIDCConfigChangedEventMapper(event)
|
2020-11-26 13:14:07 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-01-04 14:52:13 +01:00
|
|
|
return &IDPOIDCConfigChangedEvent{OIDCConfigChangedEvent: *e.(*idpconfig.OIDCConfigChangedEvent)}, nil
|
2020-11-26 13:14:07 +01:00
|
|
|
}
|