2024-09-17 15:06:22 +02:00
|
|
|
package authenticator
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/zitadel/zitadel/internal/api/http"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2024-10-01 13:55:48 +02:00
|
|
|
publicKeyPrefix = eventPrefix + "public_key."
|
2024-09-26 09:25:31 +02:00
|
|
|
PublicKeyCreatedType = publicKeyPrefix + "created"
|
|
|
|
PublicKeyDeletedType = publicKeyPrefix + "deleted"
|
2024-09-17 15:06:22 +02:00
|
|
|
)
|
|
|
|
|
2024-09-26 09:25:31 +02:00
|
|
|
type PublicKeyCreatedEvent struct {
|
2024-09-17 15:06:22 +02:00
|
|
|
*eventstore.BaseEvent `json:"-"`
|
|
|
|
|
|
|
|
UserID string `json:"userID"`
|
|
|
|
|
2024-09-24 14:26:48 +02:00
|
|
|
ExpirationDate time.Time `json:"expirationDate,omitempty"`
|
|
|
|
PublicKey []byte `json:"publicKey,omitempty"`
|
|
|
|
TriggeredAtOrigin string `json:"triggerOrigin,omitempty"`
|
2024-09-17 15:06:22 +02:00
|
|
|
}
|
|
|
|
|
2024-09-26 09:25:31 +02:00
|
|
|
func (e *PublicKeyCreatedEvent) SetBaseEvent(event *eventstore.BaseEvent) {
|
2024-09-17 15:06:22 +02:00
|
|
|
e.BaseEvent = event
|
|
|
|
}
|
|
|
|
|
2024-09-26 09:25:31 +02:00
|
|
|
func (e *PublicKeyCreatedEvent) Payload() interface{} {
|
2024-09-17 15:06:22 +02:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2024-09-26 09:25:31 +02:00
|
|
|
func (e *PublicKeyCreatedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2024-09-17 15:06:22 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-09-26 09:25:31 +02:00
|
|
|
func (e *PublicKeyCreatedEvent) TriggerOrigin() string {
|
2024-09-24 14:26:48 +02:00
|
|
|
return e.TriggeredAtOrigin
|
|
|
|
}
|
|
|
|
|
2024-09-26 09:25:31 +02:00
|
|
|
func NewPublicKeyCreatedEvent(
|
2024-09-17 15:06:22 +02:00
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
userID string,
|
|
|
|
expirationDate time.Time,
|
|
|
|
publicKey []byte,
|
2024-09-26 09:25:31 +02:00
|
|
|
) *PublicKeyCreatedEvent {
|
|
|
|
return &PublicKeyCreatedEvent{
|
2024-09-17 15:06:22 +02:00
|
|
|
BaseEvent: eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
2024-09-26 09:25:31 +02:00
|
|
|
PublicKeyCreatedType,
|
2024-09-17 15:06:22 +02:00
|
|
|
),
|
2024-09-24 14:26:48 +02:00
|
|
|
UserID: userID,
|
|
|
|
ExpirationDate: expirationDate,
|
|
|
|
PublicKey: publicKey,
|
|
|
|
TriggeredAtOrigin: http.DomainContext(ctx).Origin(),
|
2024-09-17 15:06:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-26 09:25:31 +02:00
|
|
|
type PublicKeyDeletedEvent struct {
|
2024-09-17 15:06:22 +02:00
|
|
|
*eventstore.BaseEvent `json:"-"`
|
|
|
|
}
|
|
|
|
|
2024-09-26 09:25:31 +02:00
|
|
|
func (e *PublicKeyDeletedEvent) SetBaseEvent(event *eventstore.BaseEvent) {
|
2024-09-17 15:06:22 +02:00
|
|
|
e.BaseEvent = event
|
|
|
|
}
|
|
|
|
|
2024-09-26 09:25:31 +02:00
|
|
|
func (e *PublicKeyDeletedEvent) Payload() interface{} {
|
2024-09-17 15:06:22 +02:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2024-09-26 09:25:31 +02:00
|
|
|
func (e *PublicKeyDeletedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2024-09-17 15:06:22 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-09-26 09:25:31 +02:00
|
|
|
func NewPublicKeyDeletedEvent(
|
2024-09-17 15:06:22 +02:00
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
2024-09-26 09:25:31 +02:00
|
|
|
) *PublicKeyDeletedEvent {
|
|
|
|
return &PublicKeyDeletedEvent{
|
2024-09-17 15:06:22 +02:00
|
|
|
BaseEvent: eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
2024-09-26 09:25:31 +02:00
|
|
|
PublicKeyDeletedType,
|
2024-09-17 15:06:22 +02:00
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|