2021-01-04 13:52:13 +00:00
|
|
|
package user
|
2020-12-10 15:18:52 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-02-18 13:48:27 +00:00
|
|
|
"time"
|
|
|
|
|
2022-11-30 16:01:17 +00:00
|
|
|
"golang.org/x/text/language"
|
2022-01-03 08:19:07 +00:00
|
|
|
|
2023-10-10 13:20:53 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/api/http"
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/crypto"
|
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
2022-11-30 16:01:17 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
2023-12-08 14:30:55 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
2020-12-10 15:18:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2021-01-04 13:52:13 +00:00
|
|
|
humanEventPrefix = userEventTypePrefix + "human."
|
2020-12-10 15:18:52 +00:00
|
|
|
HumanAddedType = humanEventPrefix + "added"
|
|
|
|
HumanRegisteredType = humanEventPrefix + "selfregistered"
|
|
|
|
HumanInitialCodeAddedType = humanEventPrefix + "initialization.code.added"
|
|
|
|
HumanInitialCodeSentType = humanEventPrefix + "initialization.code.sent"
|
|
|
|
HumanInitializedCheckSucceededType = humanEventPrefix + "initialization.check.succeeded"
|
|
|
|
HumanInitializedCheckFailedType = humanEventPrefix + "initialization.check.failed"
|
2024-09-11 10:53:55 +00:00
|
|
|
HumanInviteCodeAddedType = humanEventPrefix + "invite.code.added"
|
|
|
|
HumanInviteCodeSentType = humanEventPrefix + "invite.code.sent"
|
|
|
|
HumanInviteCheckSucceededType = humanEventPrefix + "invite.check.succeeded"
|
|
|
|
HumanInviteCheckFailedType = humanEventPrefix + "invite.check.failed"
|
2020-12-10 15:18:52 +00:00
|
|
|
HumanSignedOutType = humanEventPrefix + "signed.out"
|
|
|
|
)
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
type HumanAddedEvent struct {
|
2020-12-10 15:18:52 +00:00
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
2021-01-21 09:49:38 +00:00
|
|
|
UserName string `json:"userName"`
|
|
|
|
userLoginMustBeDomain bool
|
2020-12-10 15:18:52 +00:00
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
FirstName string `json:"firstName,omitempty"`
|
|
|
|
LastName string `json:"lastName,omitempty"`
|
|
|
|
NickName string `json:"nickName,omitempty"`
|
|
|
|
DisplayName string `json:"displayName,omitempty"`
|
|
|
|
PreferredLanguage language.Tag `json:"preferredLanguage,omitempty"`
|
|
|
|
Gender domain.Gender `json:"gender,omitempty"`
|
2020-12-10 15:18:52 +00:00
|
|
|
|
2023-03-14 19:20:38 +00:00
|
|
|
EmailAddress domain.EmailAddress `json:"email,omitempty"`
|
2020-12-10 15:18:52 +00:00
|
|
|
|
2023-03-14 19:20:38 +00:00
|
|
|
PhoneNumber domain.PhoneNumber `json:"phone,omitempty"`
|
2020-12-10 15:18:52 +00:00
|
|
|
|
|
|
|
Country string `json:"country,omitempty"`
|
|
|
|
Locality string `json:"locality,omitempty"`
|
|
|
|
PostalCode string `json:"postalCode,omitempty"`
|
|
|
|
Region string `json:"region,omitempty"`
|
|
|
|
StreetAddress string `json:"streetAddress,omitempty"`
|
2021-01-04 13:52:13 +00:00
|
|
|
|
2023-07-14 06:49:57 +00:00
|
|
|
// New events only use EncodedHash. However, the secret field
|
|
|
|
// is preserved to handle events older than the switch to Passwap.
|
2021-01-04 13:52:13 +00:00
|
|
|
Secret *crypto.CryptoValue `json:"secret,omitempty"`
|
2023-07-14 06:49:57 +00:00
|
|
|
EncodedHash string `json:"encodedHash,omitempty"`
|
2021-01-04 13:52:13 +00:00
|
|
|
ChangeRequired bool `json:"changeRequired,omitempty"`
|
2020-12-10 15:18:52 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanAddedEvent) Payload() interface{} {
|
2020-12-10 15:18:52 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanAddedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
|
|
|
return []*eventstore.UniqueConstraint{NewAddUsernameUniqueConstraint(e.UserName, e.Aggregate().ResourceOwner, e.userLoginMustBeDomain)}
|
2021-01-21 09:49:38 +00:00
|
|
|
}
|
|
|
|
|
2021-01-06 10:12:56 +00:00
|
|
|
func (e *HumanAddedEvent) AddAddressData(
|
|
|
|
country,
|
|
|
|
locality,
|
|
|
|
postalCode,
|
|
|
|
region,
|
|
|
|
streetAddress string,
|
|
|
|
) {
|
|
|
|
e.Country = country
|
|
|
|
e.Locality = locality
|
|
|
|
e.PostalCode = postalCode
|
|
|
|
e.Region = region
|
|
|
|
e.StreetAddress = streetAddress
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *HumanAddedEvent) AddPhoneData(
|
2023-03-14 19:20:38 +00:00
|
|
|
phoneNumber domain.PhoneNumber,
|
2021-01-06 10:12:56 +00:00
|
|
|
) {
|
|
|
|
e.PhoneNumber = phoneNumber
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *HumanAddedEvent) AddPasswordData(
|
2023-07-14 06:49:57 +00:00
|
|
|
encoded string,
|
2021-01-06 10:12:56 +00:00
|
|
|
changeRequired bool,
|
|
|
|
) {
|
2023-07-14 06:49:57 +00:00
|
|
|
e.EncodedHash = encoded
|
2021-01-06 10:12:56 +00:00
|
|
|
e.ChangeRequired = changeRequired
|
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
func NewHumanAddedEvent(
|
2020-12-10 15:18:52 +00:00
|
|
|
ctx context.Context,
|
2021-02-18 13:48:27 +00:00
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
|
2020-12-10 15:18:52 +00:00
|
|
|
userName,
|
|
|
|
firstName,
|
|
|
|
lastName,
|
|
|
|
nickName,
|
|
|
|
displayName string,
|
|
|
|
preferredLanguage language.Tag,
|
2021-01-04 13:52:13 +00:00
|
|
|
gender domain.Gender,
|
2023-03-14 19:20:38 +00:00
|
|
|
emailAddress domain.EmailAddress,
|
2021-01-21 09:49:38 +00:00
|
|
|
userLoginMustBeDomain bool,
|
2021-01-04 13:52:13 +00:00
|
|
|
) *HumanAddedEvent {
|
|
|
|
return &HumanAddedEvent{
|
2021-02-18 13:48:27 +00:00
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
2020-12-10 15:18:52 +00:00
|
|
|
ctx,
|
2021-02-18 13:48:27 +00:00
|
|
|
aggregate,
|
2020-12-10 15:18:52 +00:00
|
|
|
HumanAddedType,
|
|
|
|
),
|
2021-01-21 09:49:38 +00:00
|
|
|
UserName: userName,
|
|
|
|
FirstName: firstName,
|
|
|
|
LastName: lastName,
|
|
|
|
NickName: nickName,
|
|
|
|
DisplayName: displayName,
|
|
|
|
PreferredLanguage: preferredLanguage,
|
|
|
|
Gender: gender,
|
|
|
|
EmailAddress: emailAddress,
|
|
|
|
userLoginMustBeDomain: userLoginMustBeDomain,
|
2020-12-10 15:18:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func HumanAddedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2021-01-04 13:52:13 +00:00
|
|
|
humanAdded := &HumanAddedEvent{
|
2020-12-10 15:18:52 +00:00
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
2023-10-19 10:19:10 +00:00
|
|
|
err := event.Unmarshal(humanAdded)
|
2020-12-10 15:18:52 +00:00
|
|
|
if err != nil {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInternal(err, "USER-vGlhy", "unable to unmarshal human added")
|
2020-12-10 15:18:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return humanAdded, nil
|
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
type HumanRegisteredEvent struct {
|
2023-03-14 19:20:38 +00:00
|
|
|
eventstore.BaseEvent `json:"-"`
|
2021-01-21 09:49:38 +00:00
|
|
|
UserName string `json:"userName"`
|
|
|
|
userLoginMustBeDomain bool
|
2023-03-14 19:20:38 +00:00
|
|
|
FirstName string `json:"firstName,omitempty"`
|
|
|
|
LastName string `json:"lastName,omitempty"`
|
|
|
|
NickName string `json:"nickName,omitempty"`
|
|
|
|
DisplayName string `json:"displayName,omitempty"`
|
|
|
|
PreferredLanguage language.Tag `json:"preferredLanguage,omitempty"`
|
|
|
|
Gender domain.Gender `json:"gender,omitempty"`
|
|
|
|
EmailAddress domain.EmailAddress `json:"email,omitempty"`
|
|
|
|
PhoneNumber domain.PhoneNumber `json:"phone,omitempty"`
|
|
|
|
Country string `json:"country,omitempty"`
|
|
|
|
Locality string `json:"locality,omitempty"`
|
|
|
|
PostalCode string `json:"postalCode,omitempty"`
|
|
|
|
Region string `json:"region,omitempty"`
|
|
|
|
StreetAddress string `json:"streetAddress,omitempty"`
|
2023-07-14 06:49:57 +00:00
|
|
|
|
|
|
|
// New events only use EncodedHash. However, the secret field
|
|
|
|
// is preserved to handle events older than the switch to Passwap.
|
|
|
|
Secret *crypto.CryptoValue `json:"secret,omitempty"` // legacy
|
|
|
|
EncodedHash string `json:"encodedHash,omitempty"`
|
|
|
|
ChangeRequired bool `json:"changeRequired,omitempty"`
|
2024-04-24 15:50:58 +00:00
|
|
|
|
|
|
|
UserAgentID string `json:"userAgentID,omitempty"`
|
2020-12-10 15:18:52 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanRegisteredEvent) Payload() interface{} {
|
2020-12-10 15:18:52 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanRegisteredEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
|
|
|
return []*eventstore.UniqueConstraint{NewAddUsernameUniqueConstraint(e.UserName, e.Aggregate().ResourceOwner, e.userLoginMustBeDomain)}
|
2021-01-21 09:49:38 +00:00
|
|
|
}
|
|
|
|
|
2021-01-06 10:12:56 +00:00
|
|
|
func (e *HumanRegisteredEvent) AddAddressData(
|
|
|
|
country,
|
|
|
|
locality,
|
|
|
|
postalCode,
|
|
|
|
region,
|
|
|
|
streetAddress string,
|
|
|
|
) {
|
|
|
|
e.Country = country
|
|
|
|
e.Locality = locality
|
|
|
|
e.PostalCode = postalCode
|
|
|
|
e.Region = region
|
|
|
|
e.StreetAddress = streetAddress
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *HumanRegisteredEvent) AddPhoneData(
|
2023-03-14 19:20:38 +00:00
|
|
|
phoneNumber domain.PhoneNumber,
|
2021-01-06 10:12:56 +00:00
|
|
|
) {
|
|
|
|
e.PhoneNumber = phoneNumber
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *HumanRegisteredEvent) AddPasswordData(
|
2023-07-14 06:49:57 +00:00
|
|
|
encoded string,
|
2021-01-06 10:12:56 +00:00
|
|
|
changeRequired bool,
|
|
|
|
) {
|
2023-07-14 06:49:57 +00:00
|
|
|
e.EncodedHash = encoded
|
2021-01-06 10:12:56 +00:00
|
|
|
e.ChangeRequired = changeRequired
|
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
func NewHumanRegisteredEvent(
|
2020-12-10 15:18:52 +00:00
|
|
|
ctx context.Context,
|
2021-02-18 13:48:27 +00:00
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
|
2020-12-10 15:18:52 +00:00
|
|
|
userName,
|
|
|
|
firstName,
|
|
|
|
lastName,
|
|
|
|
nickName,
|
|
|
|
displayName string,
|
|
|
|
preferredLanguage language.Tag,
|
2021-01-04 13:52:13 +00:00
|
|
|
gender domain.Gender,
|
2023-03-14 19:20:38 +00:00
|
|
|
emailAddress domain.EmailAddress,
|
2021-01-21 09:49:38 +00:00
|
|
|
userLoginMustBeDomain bool,
|
2024-04-24 15:50:58 +00:00
|
|
|
userAgentID string,
|
2021-01-04 13:52:13 +00:00
|
|
|
) *HumanRegisteredEvent {
|
|
|
|
return &HumanRegisteredEvent{
|
2021-02-18 13:48:27 +00:00
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
2020-12-10 15:18:52 +00:00
|
|
|
ctx,
|
2021-02-18 13:48:27 +00:00
|
|
|
aggregate,
|
2020-12-10 15:18:52 +00:00
|
|
|
HumanRegisteredType,
|
|
|
|
),
|
2021-01-21 09:49:38 +00:00
|
|
|
UserName: userName,
|
|
|
|
FirstName: firstName,
|
|
|
|
LastName: lastName,
|
|
|
|
NickName: nickName,
|
|
|
|
DisplayName: displayName,
|
|
|
|
PreferredLanguage: preferredLanguage,
|
|
|
|
Gender: gender,
|
|
|
|
EmailAddress: emailAddress,
|
|
|
|
userLoginMustBeDomain: userLoginMustBeDomain,
|
2024-04-24 15:50:58 +00:00
|
|
|
UserAgentID: userAgentID,
|
2020-12-10 15:18:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func HumanRegisteredEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2021-01-04 13:52:13 +00:00
|
|
|
humanRegistered := &HumanRegisteredEvent{
|
2020-12-10 15:18:52 +00:00
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
2023-10-19 10:19:10 +00:00
|
|
|
err := event.Unmarshal(humanRegistered)
|
2020-12-10 15:18:52 +00:00
|
|
|
if err != nil {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInternal(err, "USER-3Vm9s", "unable to unmarshal human registered")
|
2020-12-10 15:18:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return humanRegistered, nil
|
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
type HumanInitialCodeAddedEvent struct {
|
2020-12-10 15:18:52 +00:00
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
Code *crypto.CryptoValue `json:"code,omitempty"`
|
|
|
|
Expiry time.Duration `json:"expiry,omitempty"`
|
2023-10-10 13:20:53 +00:00
|
|
|
TriggeredAtOrigin string `json:"triggerOrigin,omitempty"`
|
2024-04-24 15:50:58 +00:00
|
|
|
AuthRequestID string `json:"authRequestID,omitempty"`
|
2020-12-10 15:18:52 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanInitialCodeAddedEvent) Payload() interface{} {
|
2020-12-10 15:18:52 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanInitialCodeAddedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2021-01-21 09:49:38 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-10-10 13:20:53 +00:00
|
|
|
func (e *HumanInitialCodeAddedEvent) TriggerOrigin() string {
|
|
|
|
return e.TriggeredAtOrigin
|
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
func NewHumanInitialCodeAddedEvent(
|
2020-12-10 15:18:52 +00:00
|
|
|
ctx context.Context,
|
2021-02-18 13:48:27 +00:00
|
|
|
aggregate *eventstore.Aggregate,
|
2020-12-10 15:18:52 +00:00
|
|
|
code *crypto.CryptoValue,
|
|
|
|
expiry time.Duration,
|
2024-04-24 15:50:58 +00:00
|
|
|
authRequestID string,
|
2021-01-04 13:52:13 +00:00
|
|
|
) *HumanInitialCodeAddedEvent {
|
|
|
|
return &HumanInitialCodeAddedEvent{
|
2020-12-10 15:18:52 +00:00
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
2021-02-18 13:48:27 +00:00
|
|
|
aggregate,
|
2020-12-10 15:18:52 +00:00
|
|
|
HumanInitialCodeAddedType,
|
|
|
|
),
|
2023-10-10 13:20:53 +00:00
|
|
|
Code: code,
|
|
|
|
Expiry: expiry,
|
feat: trusted (instance) domains (#8369)
# Which Problems Are Solved
ZITADEL currently selects the instance context based on a HTTP header
(see https://github.com/zitadel/zitadel/issues/8279#issue-2399959845 and
checks it against the list of instance domains. Let's call it instance
or API domain.
For any context based URL (e.g. OAuth, OIDC, SAML endpoints, links in
emails, ...) the requested domain (instance domain) will be used. Let's
call it the public domain.
In cases of proxied setups, all exposed domains (public domains) require
the domain to be managed as instance domain.
This can either be done using the "ExternalDomain" in the runtime config
or via system API, which requires a validation through CustomerPortal on
zitadel.cloud.
# How the Problems Are Solved
- Two new headers / header list are added:
- `InstanceHostHeaders`: an ordered list (first sent wins), which will
be used to match the instance.
(For backward compatibility: the `HTTP1HostHeader`, `HTTP2HostHeader`
and `forwarded`, `x-forwarded-for`, `x-forwarded-host` are checked
afterwards as well)
- `PublicHostHeaders`: an ordered list (first sent wins), which will be
used as public host / domain. This will be checked against a list of
trusted domains on the instance.
- The middleware intercepts all requests to the API and passes a
`DomainCtx` object with the hosts and protocol into the context
(previously only a computed `origin` was passed)
- HTTP / GRPC server do not longer try to match the headers to instances
themself, but use the passed `http.DomainContext` in their interceptors.
- The `RequestedHost` and `RequestedDomain` from authz.Instance are
removed in favor of the `http.DomainContext`
- When authenticating to or signing out from Console UI, the current
`http.DomainContext(ctx).Origin` (already checked by instance
interceptor for validity) is used to compute and dynamically add a
`redirect_uri` and `post_logout_redirect_uri`.
- Gateway passes all configured host headers (previously only did
`x-zitadel-*`)
- Admin API allows to manage trusted domain
# Additional Changes
None
# Additional Context
- part of #8279
- open topics:
- "single-instance" mode
- Console UI
2024-07-31 15:00:38 +00:00
|
|
|
TriggeredAtOrigin: http.DomainContext(ctx).Origin(),
|
2024-04-24 15:50:58 +00:00
|
|
|
AuthRequestID: authRequestID,
|
2020-12-10 15:18:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func HumanInitialCodeAddedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2021-01-04 13:52:13 +00:00
|
|
|
humanRegistered := &HumanInitialCodeAddedEvent{
|
2020-12-10 15:18:52 +00:00
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
2023-10-19 10:19:10 +00:00
|
|
|
err := event.Unmarshal(humanRegistered)
|
2020-12-10 15:18:52 +00:00
|
|
|
if err != nil {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInternal(err, "USER-bM9se", "unable to unmarshal human initial code added")
|
2020-12-10 15:18:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return humanRegistered, nil
|
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
type HumanInitialCodeSentEvent struct {
|
2020-12-10 15:18:52 +00:00
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanInitialCodeSentEvent) Payload() interface{} {
|
2020-12-10 15:18:52 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanInitialCodeSentEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2021-01-21 09:49:38 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-02-18 13:48:27 +00:00
|
|
|
func NewHumanInitialCodeSentEvent(ctx context.Context, aggregate *eventstore.Aggregate) *HumanInitialCodeSentEvent {
|
2021-01-04 13:52:13 +00:00
|
|
|
return &HumanInitialCodeSentEvent{
|
2020-12-10 15:18:52 +00:00
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
2021-02-18 13:48:27 +00:00
|
|
|
aggregate,
|
2020-12-10 15:18:52 +00:00
|
|
|
HumanInitialCodeSentType,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func HumanInitialCodeSentEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2021-01-04 13:52:13 +00:00
|
|
|
return &HumanInitialCodeSentEvent{
|
2020-12-10 15:18:52 +00:00
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
type HumanInitializedCheckSucceededEvent struct {
|
2020-12-10 15:18:52 +00:00
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanInitializedCheckSucceededEvent) Payload() interface{} {
|
2020-12-10 15:18:52 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanInitializedCheckSucceededEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2021-01-21 09:49:38 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-02-18 13:48:27 +00:00
|
|
|
func NewHumanInitializedCheckSucceededEvent(ctx context.Context, aggregate *eventstore.Aggregate) *HumanInitializedCheckSucceededEvent {
|
2021-01-04 13:52:13 +00:00
|
|
|
return &HumanInitializedCheckSucceededEvent{
|
2020-12-10 15:18:52 +00:00
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
2021-02-18 13:48:27 +00:00
|
|
|
aggregate,
|
2020-12-10 15:18:52 +00:00
|
|
|
HumanInitializedCheckSucceededType,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func HumanInitializedCheckSucceededEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2021-01-04 13:52:13 +00:00
|
|
|
return &HumanInitializedCheckSucceededEvent{
|
2020-12-10 15:18:52 +00:00
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
type HumanInitializedCheckFailedEvent struct {
|
2020-12-10 15:18:52 +00:00
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanInitializedCheckFailedEvent) Payload() interface{} {
|
2020-12-10 15:18:52 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanInitializedCheckFailedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2021-01-21 09:49:38 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-02-18 13:48:27 +00:00
|
|
|
func NewHumanInitializedCheckFailedEvent(ctx context.Context, aggregate *eventstore.Aggregate) *HumanInitializedCheckFailedEvent {
|
2021-01-04 13:52:13 +00:00
|
|
|
return &HumanInitializedCheckFailedEvent{
|
2020-12-10 15:18:52 +00:00
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
2021-02-18 13:48:27 +00:00
|
|
|
aggregate,
|
2020-12-10 15:18:52 +00:00
|
|
|
HumanInitializedCheckFailedType,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func HumanInitializedCheckFailedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2021-01-04 13:52:13 +00:00
|
|
|
return &HumanInitializedCheckFailedEvent{
|
2020-12-10 15:18:52 +00:00
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2024-09-11 10:53:55 +00:00
|
|
|
type HumanInviteCodeAddedEvent struct {
|
|
|
|
*eventstore.BaseEvent `json:"-"`
|
|
|
|
Code *crypto.CryptoValue `json:"code,omitempty"`
|
|
|
|
Expiry time.Duration `json:"expiry,omitempty"`
|
|
|
|
TriggeredAtOrigin string `json:"triggerOrigin,omitempty"`
|
|
|
|
URLTemplate string `json:"urlTemplate,omitempty"`
|
|
|
|
CodeReturned bool `json:"codeReturned,omitempty"`
|
|
|
|
ApplicationName string `json:"applicationName,omitempty"`
|
|
|
|
AuthRequestID string `json:"authRequestID,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *HumanInviteCodeAddedEvent) SetBaseEvent(b *eventstore.BaseEvent) {
|
|
|
|
e.BaseEvent = b
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *HumanInviteCodeAddedEvent) Payload() interface{} {
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *HumanInviteCodeAddedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *HumanInviteCodeAddedEvent) TriggerOrigin() string {
|
|
|
|
return e.TriggeredAtOrigin
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewHumanInviteCodeAddedEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
code *crypto.CryptoValue,
|
|
|
|
expiry time.Duration,
|
|
|
|
urlTemplate string,
|
|
|
|
codeReturned bool,
|
|
|
|
applicationName string,
|
|
|
|
authRequestID string,
|
|
|
|
) *HumanInviteCodeAddedEvent {
|
|
|
|
return &HumanInviteCodeAddedEvent{
|
|
|
|
BaseEvent: eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
HumanInviteCodeAddedType,
|
|
|
|
),
|
|
|
|
Code: code,
|
|
|
|
Expiry: expiry,
|
|
|
|
TriggeredAtOrigin: http.DomainContext(ctx).Origin(),
|
|
|
|
URLTemplate: urlTemplate,
|
|
|
|
CodeReturned: codeReturned,
|
|
|
|
ApplicationName: applicationName,
|
|
|
|
AuthRequestID: authRequestID,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type HumanInviteCodeSentEvent struct {
|
|
|
|
*eventstore.BaseEvent `json:"-"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *HumanInviteCodeSentEvent) SetBaseEvent(b *eventstore.BaseEvent) {
|
|
|
|
e.BaseEvent = b
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *HumanInviteCodeSentEvent) Payload() interface{} {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *HumanInviteCodeSentEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewHumanInviteCodeSentEvent(ctx context.Context, aggregate *eventstore.Aggregate) *HumanInviteCodeSentEvent {
|
|
|
|
return &HumanInviteCodeSentEvent{
|
|
|
|
BaseEvent: eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
HumanInviteCodeSentType,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type HumanInviteCheckSucceededEvent struct {
|
|
|
|
*eventstore.BaseEvent `json:"-"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *HumanInviteCheckSucceededEvent) SetBaseEvent(b *eventstore.BaseEvent) {
|
|
|
|
e.BaseEvent = b
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *HumanInviteCheckSucceededEvent) Payload() interface{} {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *HumanInviteCheckSucceededEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewHumanInviteCheckSucceededEvent(ctx context.Context, aggregate *eventstore.Aggregate) *HumanInviteCheckSucceededEvent {
|
|
|
|
return &HumanInviteCheckSucceededEvent{
|
|
|
|
BaseEvent: eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
HumanInviteCheckSucceededType,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type HumanInviteCheckFailedEvent struct {
|
|
|
|
*eventstore.BaseEvent `json:"-"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *HumanInviteCheckFailedEvent) SetBaseEvent(b *eventstore.BaseEvent) {
|
|
|
|
e.BaseEvent = b
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *HumanInviteCheckFailedEvent) Payload() interface{} {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *HumanInviteCheckFailedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewHumanInviteCheckFailedEvent(ctx context.Context, aggregate *eventstore.Aggregate) *HumanInviteCheckFailedEvent {
|
|
|
|
return &HumanInviteCheckFailedEvent{
|
|
|
|
BaseEvent: eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
HumanInviteCheckFailedType,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
type HumanSignedOutEvent struct {
|
2020-12-10 15:18:52 +00:00
|
|
|
eventstore.BaseEvent `json:"-"`
|
2021-02-08 10:30:30 +00:00
|
|
|
|
2024-10-31 14:57:17 +00:00
|
|
|
UserAgentID string `json:"userAgentID"`
|
|
|
|
SessionID string `json:"sessionID,omitempty"`
|
|
|
|
TriggeredAtOrigin string `json:"triggerOrigin,omitempty"`
|
2020-12-10 15:18:52 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanSignedOutEvent) Payload() interface{} {
|
2021-03-26 15:29:26 +00:00
|
|
|
return e
|
2020-12-10 15:18:52 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanSignedOutEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2021-01-21 09:49:38 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-10-31 14:57:17 +00:00
|
|
|
func (e *HumanSignedOutEvent) TriggerOrigin() string {
|
|
|
|
return e.TriggeredAtOrigin
|
|
|
|
}
|
|
|
|
|
2021-02-18 13:48:27 +00:00
|
|
|
func NewHumanSignedOutEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
2024-10-31 14:57:17 +00:00
|
|
|
userAgentID,
|
|
|
|
sessionID string,
|
2021-02-18 13:48:27 +00:00
|
|
|
) *HumanSignedOutEvent {
|
2021-01-04 13:52:13 +00:00
|
|
|
return &HumanSignedOutEvent{
|
2020-12-10 15:18:52 +00:00
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
2021-02-18 13:48:27 +00:00
|
|
|
aggregate,
|
2020-12-10 15:18:52 +00:00
|
|
|
HumanSignedOutType,
|
|
|
|
),
|
2024-10-31 14:57:17 +00:00
|
|
|
UserAgentID: userAgentID,
|
|
|
|
SessionID: sessionID,
|
|
|
|
TriggeredAtOrigin: http.DomainContext(ctx).Origin(),
|
2020-12-10 15:18:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func HumanSignedOutEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2023-01-10 14:58:10 +00:00
|
|
|
signedOut := &HumanSignedOutEvent{
|
2020-12-10 15:18:52 +00:00
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
2023-01-10 14:58:10 +00:00
|
|
|
}
|
2023-10-19 10:19:10 +00:00
|
|
|
err := event.Unmarshal(signedOut)
|
2023-01-10 14:58:10 +00:00
|
|
|
if err != nil {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInternal(err, "USER-WFS3g", "unable to unmarshal human signed out")
|
2023-01-10 14:58:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return signedOut, nil
|
2020-12-10 15:18:52 +00:00
|
|
|
}
|