2023-07-10 13:27:00 +00:00
|
|
|
package oidcsession
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
2024-05-16 05:07:56 +00:00
|
|
|
"golang.org/x/text/language"
|
|
|
|
|
2023-07-12 12:24:01 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
2023-07-10 13:27:00 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
oidcSessionEventPrefix = "oidc_session."
|
|
|
|
AddedType = oidcSessionEventPrefix + "added"
|
|
|
|
AccessTokenAddedType = oidcSessionEventPrefix + "access_token.added"
|
2023-07-17 12:33:37 +00:00
|
|
|
AccessTokenRevokedType = oidcSessionEventPrefix + "access_token.revoked"
|
2023-07-10 13:27:00 +00:00
|
|
|
RefreshTokenAddedType = oidcSessionEventPrefix + "refresh_token.added"
|
|
|
|
RefreshTokenRenewedType = oidcSessionEventPrefix + "refresh_token.renewed"
|
2023-07-17 12:33:37 +00:00
|
|
|
RefreshTokenRevokedType = oidcSessionEventPrefix + "refresh_token.revoked"
|
2023-07-10 13:27:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type AddedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
2024-05-16 05:07:56 +00:00
|
|
|
UserID string `json:"userID"`
|
|
|
|
UserResourceOwner string `json:"userResourceOwner"`
|
|
|
|
SessionID string `json:"sessionID"`
|
|
|
|
ClientID string `json:"clientID"`
|
|
|
|
Audience []string `json:"audience"`
|
|
|
|
Scope []string `json:"scope"`
|
|
|
|
AuthMethods []domain.UserAuthMethodType `json:"authMethods"`
|
|
|
|
AuthTime time.Time `json:"authTime"`
|
|
|
|
Nonce string `json:"nonce,omitempty"`
|
|
|
|
PreferredLanguage *language.Tag `json:"preferredLanguage,omitempty"`
|
|
|
|
UserAgent *domain.UserAgent `json:"userAgent,omitempty"`
|
2023-07-10 13:27:00 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *AddedEvent) Payload() interface{} {
|
2023-07-10 13:27:00 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *AddedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-07-10 13:27:00 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-07-17 12:33:37 +00:00
|
|
|
func (e *AddedEvent) SetBaseEvent(event *eventstore.BaseEvent) {
|
|
|
|
e.BaseEvent = *event
|
|
|
|
}
|
|
|
|
|
2023-07-10 13:27:00 +00:00
|
|
|
func NewAddedEvent(ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
userID,
|
2024-05-16 05:07:56 +00:00
|
|
|
userResourceOwner,
|
2023-07-10 13:27:00 +00:00
|
|
|
sessionID,
|
|
|
|
clientID string,
|
|
|
|
audience,
|
|
|
|
scope []string,
|
2023-07-12 12:24:01 +00:00
|
|
|
authMethods []domain.UserAuthMethodType,
|
2023-07-10 13:27:00 +00:00
|
|
|
authTime time.Time,
|
2024-05-16 05:07:56 +00:00
|
|
|
nonce string,
|
|
|
|
preferredLanguage *language.Tag,
|
|
|
|
userAgent *domain.UserAgent,
|
2023-07-10 13:27:00 +00:00
|
|
|
) *AddedEvent {
|
|
|
|
return &AddedEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
AddedType,
|
|
|
|
),
|
2024-05-16 05:07:56 +00:00
|
|
|
UserID: userID,
|
|
|
|
UserResourceOwner: userResourceOwner,
|
|
|
|
SessionID: sessionID,
|
|
|
|
ClientID: clientID,
|
|
|
|
Audience: audience,
|
|
|
|
Scope: scope,
|
|
|
|
AuthMethods: authMethods,
|
|
|
|
AuthTime: authTime,
|
|
|
|
Nonce: nonce,
|
|
|
|
PreferredLanguage: preferredLanguage,
|
|
|
|
UserAgent: userAgent,
|
2023-07-10 13:27:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type AccessTokenAddedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
2024-03-20 10:18:46 +00:00
|
|
|
ID string `json:"id,omitempty"`
|
|
|
|
Scope []string `json:"scope,omitempty"`
|
|
|
|
Lifetime time.Duration `json:"lifetime,omitempty"`
|
|
|
|
Reason domain.TokenReason `json:"reason,omitempty"`
|
|
|
|
Actor *domain.TokenActor `json:"actor,omitempty"`
|
2023-07-10 13:27:00 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *AccessTokenAddedEvent) Payload() interface{} {
|
2023-07-10 13:27:00 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *AccessTokenAddedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-07-10 13:27:00 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-07-17 12:33:37 +00:00
|
|
|
func (e *AccessTokenAddedEvent) SetBaseEvent(event *eventstore.BaseEvent) {
|
|
|
|
e.BaseEvent = *event
|
|
|
|
}
|
|
|
|
|
2023-07-10 13:27:00 +00:00
|
|
|
func NewAccessTokenAddedEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
id string,
|
|
|
|
scope []string,
|
|
|
|
lifetime time.Duration,
|
2024-03-20 10:18:46 +00:00
|
|
|
reason domain.TokenReason,
|
|
|
|
actor *domain.TokenActor,
|
2023-07-10 13:27:00 +00:00
|
|
|
) *AccessTokenAddedEvent {
|
|
|
|
return &AccessTokenAddedEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
AccessTokenAddedType,
|
|
|
|
),
|
|
|
|
ID: id,
|
|
|
|
Scope: scope,
|
|
|
|
Lifetime: lifetime,
|
2024-03-20 10:18:46 +00:00
|
|
|
Reason: reason,
|
|
|
|
Actor: actor,
|
2023-07-10 13:27:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-17 12:33:37 +00:00
|
|
|
type AccessTokenRevokedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
}
|
2023-07-10 13:27:00 +00:00
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *AccessTokenRevokedEvent) Payload() interface{} {
|
2023-07-17 12:33:37 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *AccessTokenRevokedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-07-17 12:33:37 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *AccessTokenRevokedEvent) SetBaseEvent(event *eventstore.BaseEvent) {
|
|
|
|
e.BaseEvent = *event
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewAccessTokenRevokedEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
) *AccessTokenAddedEvent {
|
|
|
|
return &AccessTokenAddedEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
AccessTokenRevokedType,
|
|
|
|
),
|
|
|
|
}
|
2023-07-10 13:27:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type RefreshTokenAddedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
|
|
|
ID string `json:"id"`
|
|
|
|
Lifetime time.Duration `json:"lifetime"`
|
|
|
|
IdleLifetime time.Duration `json:"idleLifetime"`
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *RefreshTokenAddedEvent) Payload() interface{} {
|
2023-07-10 13:27:00 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *RefreshTokenAddedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-07-10 13:27:00 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-07-17 12:33:37 +00:00
|
|
|
func (e *RefreshTokenAddedEvent) SetBaseEvent(event *eventstore.BaseEvent) {
|
|
|
|
e.BaseEvent = *event
|
|
|
|
}
|
|
|
|
|
2023-07-10 13:27:00 +00:00
|
|
|
func NewRefreshTokenAddedEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
id string,
|
|
|
|
lifetime,
|
|
|
|
idleLifetime time.Duration,
|
|
|
|
) *RefreshTokenAddedEvent {
|
|
|
|
return &RefreshTokenAddedEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
RefreshTokenAddedType,
|
|
|
|
),
|
|
|
|
ID: id,
|
|
|
|
Lifetime: lifetime,
|
|
|
|
IdleLifetime: idleLifetime,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type RefreshTokenRenewedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
|
|
|
ID string `json:"id"`
|
|
|
|
IdleLifetime time.Duration `json:"idleLifetime"`
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *RefreshTokenRenewedEvent) Payload() interface{} {
|
2023-07-10 13:27:00 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *RefreshTokenRenewedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-07-10 13:27:00 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-07-17 12:33:37 +00:00
|
|
|
func (e *RefreshTokenRenewedEvent) SetBaseEvent(event *eventstore.BaseEvent) {
|
|
|
|
e.BaseEvent = *event
|
|
|
|
}
|
|
|
|
|
2023-07-10 13:27:00 +00:00
|
|
|
func NewRefreshTokenRenewedEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
id string,
|
|
|
|
idleLifetime time.Duration,
|
|
|
|
) *RefreshTokenRenewedEvent {
|
|
|
|
return &RefreshTokenRenewedEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
RefreshTokenRenewedType,
|
|
|
|
),
|
|
|
|
ID: id,
|
|
|
|
IdleLifetime: idleLifetime,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-17 12:33:37 +00:00
|
|
|
type RefreshTokenRevokedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
}
|
2023-07-10 13:27:00 +00:00
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *RefreshTokenRevokedEvent) Payload() interface{} {
|
2023-07-17 12:33:37 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *RefreshTokenRevokedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-07-17 12:33:37 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *RefreshTokenRevokedEvent) SetBaseEvent(event *eventstore.BaseEvent) {
|
|
|
|
e.BaseEvent = *event
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewRefreshTokenRevokedEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
) *RefreshTokenRevokedEvent {
|
|
|
|
return &RefreshTokenRevokedEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
RefreshTokenRevokedType,
|
|
|
|
),
|
|
|
|
}
|
2023-07-10 13:27:00 +00:00
|
|
|
}
|