68 lines
1.7 KiB
Go
Raw Normal View History

2020-11-25 20:04:32 +01:00
package oidc
import (
"encoding/json"
"github.com/caos/zitadel/internal/crypto"
"github.com/caos/zitadel/internal/errors"
"github.com/caos/zitadel/internal/eventstore/v2"
"github.com/caos/zitadel/internal/eventstore/v2/repository"
)
2020-11-30 10:41:10 +01:00
const (
ConfigAddedEventType eventstore.EventType = "oidc.config.added"
)
2020-11-25 20:04:32 +01:00
type ConfigAddedEvent struct {
eventstore.BaseEvent
IDPConfigID string `json:"idpConfigId"`
2020-11-27 11:30:56 +01:00
ClientID string `json:"clientId,omitempty"`
ClientSecret *crypto.CryptoValue `json:"clientSecret,omitempty"`
Issuer string `json:"issuer,omitempty"`
Scopes []string `json:"scpoes,omitempty"`
2020-11-25 20:04:32 +01:00
2020-11-27 11:30:56 +01:00
IDPDisplayNameMapping MappingField `json:"idpDisplayNameMapping,omitempty"`
UserNameMapping MappingField `json:"usernameMapping,omitempty"`
2020-11-25 20:04:32 +01:00
}
func (e *ConfigAddedEvent) Data() interface{} {
return e
}
func NewConfigAddedEvent(
base *eventstore.BaseEvent,
clientID,
idpConfigID,
issuer string,
clientSecret *crypto.CryptoValue,
idpDisplayNameMapping,
userNameMapping MappingField,
scopes ...string,
) *ConfigAddedEvent {
return &ConfigAddedEvent{
BaseEvent: *base,
IDPConfigID: idpConfigID,
ClientID: clientID,
ClientSecret: clientSecret,
Issuer: issuer,
Scopes: scopes,
IDPDisplayNameMapping: idpDisplayNameMapping,
UserNameMapping: userNameMapping,
}
}
func ConfigAddedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
2020-11-25 20:04:32 +01:00
e := &ConfigAddedEvent{
BaseEvent: *eventstore.BaseEventFromRepo(event),
}
err := json.Unmarshal(event.Data, e)
if err != nil {
return nil, errors.ThrowInternal(err, "OIDC-plaBZ", "unable to unmarshal event")
}
return e, nil
}