91 lines
1.8 KiB
Go
Raw Normal View History

package authenticator
import (
"context"
"time"
"github.com/zitadel/zitadel/internal/api/http"
"github.com/zitadel/zitadel/internal/eventstore"
)
const (
jwtPrefix = eventPrefix + "jwt."
JWTCreatedType = jwtPrefix + "created"
JWTDeletedType = jwtPrefix + "deleted"
)
type JWTCreatedEvent struct {
*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"`
}
func (e *JWTCreatedEvent) SetBaseEvent(event *eventstore.BaseEvent) {
e.BaseEvent = event
}
func (e *JWTCreatedEvent) Payload() interface{} {
return e
}
func (e *JWTCreatedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
return nil
}
2024-09-24 14:26:48 +02:00
func (e *JWTCreatedEvent) TriggerOrigin() string {
return e.TriggeredAtOrigin
}
func NewJWTCreatedEvent(
ctx context.Context,
aggregate *eventstore.Aggregate,
userID string,
expirationDate time.Time,
publicKey []byte,
) *JWTCreatedEvent {
return &JWTCreatedEvent{
BaseEvent: eventstore.NewBaseEventForPush(
ctx,
aggregate,
JWTCreatedType,
),
2024-09-24 14:26:48 +02:00
UserID: userID,
ExpirationDate: expirationDate,
PublicKey: publicKey,
TriggeredAtOrigin: http.DomainContext(ctx).Origin(),
}
}
type JWTDeletedEvent struct {
*eventstore.BaseEvent `json:"-"`
}
func (e *JWTDeletedEvent) SetBaseEvent(event *eventstore.BaseEvent) {
e.BaseEvent = event
}
func (e *JWTDeletedEvent) Payload() interface{} {
return e
}
func (e *JWTDeletedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
return nil
}
func NewJWTDeletedEvent(
ctx context.Context,
aggregate *eventstore.Aggregate,
) *JWTDeletedEvent {
return &JWTDeletedEvent{
BaseEvent: eventstore.NewBaseEventForPush(
ctx,
aggregate,
JWTDeletedType,
),
}
}