2021-01-04 13:52:13 +00:00
|
|
|
package user
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-08-15 12:47:05 +00:00
|
|
|
"time"
|
2021-08-18 15:04:56 +00:00
|
|
|
|
2023-10-13 14:45:38 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/api/http"
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/crypto"
|
2023-10-19 10:19:10 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
2024-09-26 07:14:33 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/notification/senders"
|
2023-12-08 14:30:55 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
2021-01-04 13:52:13 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2023-08-02 16:57:53 +00:00
|
|
|
otpEventPrefix = mfaEventPrefix + "otp."
|
|
|
|
HumanMFAOTPAddedType = otpEventPrefix + "added"
|
|
|
|
HumanMFAOTPVerifiedType = otpEventPrefix + "verified"
|
|
|
|
HumanMFAOTPRemovedType = otpEventPrefix + "removed"
|
|
|
|
HumanMFAOTPCheckSucceededType = otpEventPrefix + "check.succeeded"
|
|
|
|
HumanMFAOTPCheckFailedType = otpEventPrefix + "check.failed"
|
|
|
|
otpSMSEventPrefix = otpEventPrefix + "sms."
|
|
|
|
HumanOTPSMSAddedType = otpSMSEventPrefix + "added"
|
|
|
|
HumanOTPSMSRemovedType = otpSMSEventPrefix + "removed"
|
2023-08-15 12:47:05 +00:00
|
|
|
HumanOTPSMSCodeAddedType = otpSMSEventPrefix + "code.added"
|
|
|
|
HumanOTPSMSCodeSentType = otpSMSEventPrefix + "code.sent"
|
2023-08-02 16:57:53 +00:00
|
|
|
HumanOTPSMSCheckSucceededType = otpSMSEventPrefix + "check.succeeded"
|
|
|
|
HumanOTPSMSCheckFailedType = otpSMSEventPrefix + "check.failed"
|
|
|
|
otpEmailEventPrefix = otpEventPrefix + "email."
|
|
|
|
HumanOTPEmailAddedType = otpEmailEventPrefix + "added"
|
|
|
|
HumanOTPEmailRemovedType = otpEmailEventPrefix + "removed"
|
2023-08-15 12:47:05 +00:00
|
|
|
HumanOTPEmailCodeAddedType = otpEmailEventPrefix + "code.added"
|
|
|
|
HumanOTPEmailCodeSentType = otpEmailEventPrefix + "code.sent"
|
2023-08-02 16:57:53 +00:00
|
|
|
HumanOTPEmailCheckSucceededType = otpEmailEventPrefix + "check.succeeded"
|
|
|
|
HumanOTPEmailCheckFailedType = otpEmailEventPrefix + "check.failed"
|
2021-01-04 13:52:13 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type HumanOTPAddedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
|
|
|
Secret *crypto.CryptoValue `json:"otpSecret,omitempty"`
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanOTPAddedEvent) Payload() interface{} {
|
2021-01-04 13:52:13 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanOTPAddedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2021-01-21 09:49:38 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-02-18 13:48:27 +00:00
|
|
|
func NewHumanOTPAddedEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
secret *crypto.CryptoValue,
|
|
|
|
) *HumanOTPAddedEvent {
|
2021-01-04 13:52:13 +00:00
|
|
|
return &HumanOTPAddedEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
2021-02-18 13:48:27 +00:00
|
|
|
aggregate,
|
2021-01-04 13:52:13 +00:00
|
|
|
HumanMFAOTPAddedType,
|
|
|
|
),
|
|
|
|
Secret: secret,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func HumanOTPAddedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2021-01-04 13:52:13 +00:00
|
|
|
otpAdded := &HumanOTPAddedEvent{
|
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
2023-10-19 10:19:10 +00:00
|
|
|
err := event.Unmarshal(otpAdded)
|
2021-01-04 13:52:13 +00:00
|
|
|
if err != nil {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInternal(err, "USER-Ns9df", "unable to unmarshal human otp added")
|
2021-01-04 13:52:13 +00:00
|
|
|
}
|
|
|
|
return otpAdded, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type HumanOTPVerifiedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
2021-01-15 08:32:59 +00:00
|
|
|
UserAgentID string `json:"userAgentID,omitempty"`
|
2021-01-04 13:52:13 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanOTPVerifiedEvent) Payload() interface{} {
|
2021-08-18 15:04:56 +00:00
|
|
|
return e
|
2021-01-04 13:52:13 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanOTPVerifiedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2021-01-21 09:49:38 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-02-18 13:48:27 +00:00
|
|
|
func NewHumanOTPVerifiedEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
userAgentID string,
|
|
|
|
) *HumanOTPVerifiedEvent {
|
2021-01-04 13:52:13 +00:00
|
|
|
return &HumanOTPVerifiedEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
2021-02-18 13:48:27 +00:00
|
|
|
aggregate,
|
2021-01-04 13:52:13 +00:00
|
|
|
HumanMFAOTPVerifiedType,
|
|
|
|
),
|
2021-01-15 08:32:59 +00:00
|
|
|
UserAgentID: userAgentID,
|
2021-01-04 13:52:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func HumanOTPVerifiedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2021-01-04 13:52:13 +00:00
|
|
|
return &HumanOTPVerifiedEvent{
|
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type HumanOTPRemovedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanOTPRemovedEvent) Payload() interface{} {
|
2021-01-04 13:52:13 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanOTPRemovedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2021-01-21 09:49:38 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-02-18 13:48:27 +00:00
|
|
|
func NewHumanOTPRemovedEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
) *HumanOTPRemovedEvent {
|
2021-01-04 13:52:13 +00:00
|
|
|
return &HumanOTPRemovedEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
2021-02-18 13:48:27 +00:00
|
|
|
aggregate,
|
2021-01-04 13:52:13 +00:00
|
|
|
HumanMFAOTPRemovedType,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func HumanOTPRemovedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2021-01-04 13:52:13 +00:00
|
|
|
return &HumanOTPRemovedEvent{
|
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type HumanOTPCheckSucceededEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
2021-02-08 10:30:30 +00:00
|
|
|
*AuthRequestInfo
|
2021-01-04 13:52:13 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanOTPCheckSucceededEvent) Payload() interface{} {
|
2021-02-08 10:30:30 +00:00
|
|
|
return e
|
2021-01-04 13:52:13 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanOTPCheckSucceededEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2021-01-21 09:49:38 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-02-18 13:48:27 +00:00
|
|
|
func NewHumanOTPCheckSucceededEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
info *AuthRequestInfo,
|
|
|
|
) *HumanOTPCheckSucceededEvent {
|
2021-01-04 13:52:13 +00:00
|
|
|
return &HumanOTPCheckSucceededEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
2021-02-18 13:48:27 +00:00
|
|
|
aggregate,
|
2021-01-04 13:52:13 +00:00
|
|
|
HumanMFAOTPCheckSucceededType,
|
|
|
|
),
|
2021-02-08 10:30:30 +00:00
|
|
|
AuthRequestInfo: info,
|
2021-01-04 13:52:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func HumanOTPCheckSucceededEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2021-02-08 10:30:30 +00:00
|
|
|
otpAdded := &HumanOTPCheckSucceededEvent{
|
2021-01-04 13:52:13 +00:00
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
2021-02-08 10:30:30 +00:00
|
|
|
}
|
2023-10-19 10:19:10 +00:00
|
|
|
err := event.Unmarshal(otpAdded)
|
2021-02-08 10:30:30 +00:00
|
|
|
if err != nil {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInternal(err, "USER-Ns9df", "unable to unmarshal human otp check succeeded")
|
2021-02-08 10:30:30 +00:00
|
|
|
}
|
|
|
|
return otpAdded, nil
|
2021-01-04 13:52:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type HumanOTPCheckFailedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
2021-02-08 10:30:30 +00:00
|
|
|
*AuthRequestInfo
|
2021-01-04 13:52:13 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanOTPCheckFailedEvent) Payload() interface{} {
|
2021-02-08 10:30:30 +00:00
|
|
|
return e
|
2021-01-04 13:52:13 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanOTPCheckFailedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2021-01-21 09:49:38 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-02-18 13:48:27 +00:00
|
|
|
func NewHumanOTPCheckFailedEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
info *AuthRequestInfo,
|
|
|
|
) *HumanOTPCheckFailedEvent {
|
2021-01-04 13:52:13 +00:00
|
|
|
return &HumanOTPCheckFailedEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
2021-02-18 13:48:27 +00:00
|
|
|
aggregate,
|
2021-01-04 13:52:13 +00:00
|
|
|
HumanMFAOTPCheckFailedType,
|
|
|
|
),
|
2021-02-08 10:30:30 +00:00
|
|
|
AuthRequestInfo: info,
|
2021-01-04 13:52:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func HumanOTPCheckFailedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2021-02-08 10:30:30 +00:00
|
|
|
otpAdded := &HumanOTPCheckFailedEvent{
|
2021-01-04 13:52:13 +00:00
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
2021-02-08 10:30:30 +00:00
|
|
|
}
|
2023-10-19 10:19:10 +00:00
|
|
|
err := event.Unmarshal(otpAdded)
|
2021-02-08 10:30:30 +00:00
|
|
|
if err != nil {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInternal(err, "USER-Ns9df", "unable to unmarshal human otp check failed")
|
2021-02-08 10:30:30 +00:00
|
|
|
}
|
|
|
|
return otpAdded, nil
|
2021-01-04 13:52:13 +00:00
|
|
|
}
|
2023-08-02 16:57:53 +00:00
|
|
|
|
|
|
|
type HumanOTPSMSAddedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanOTPSMSAddedEvent) Payload() interface{} {
|
2023-08-02 16:57:53 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanOTPSMSAddedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-08-02 16:57:53 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *HumanOTPSMSAddedEvent) SetBaseEvent(event *eventstore.BaseEvent) {
|
|
|
|
e.BaseEvent = *event
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewHumanOTPSMSAddedEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
) *HumanOTPSMSAddedEvent {
|
|
|
|
return &HumanOTPSMSAddedEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
HumanOTPSMSAddedType,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type HumanOTPSMSRemovedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanOTPSMSRemovedEvent) Payload() interface{} {
|
2023-08-02 16:57:53 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanOTPSMSRemovedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-08-02 16:57:53 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *HumanOTPSMSRemovedEvent) SetBaseEvent(event *eventstore.BaseEvent) {
|
|
|
|
e.BaseEvent = *event
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewHumanOTPSMSRemovedEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
) *HumanOTPSMSRemovedEvent {
|
|
|
|
return &HumanOTPSMSRemovedEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
HumanOTPSMSRemovedType,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-15 12:47:05 +00:00
|
|
|
type HumanOTPSMSCodeAddedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
2023-10-13 14:45:38 +00:00
|
|
|
Code *crypto.CryptoValue `json:"code,omitempty"`
|
|
|
|
Expiry time.Duration `json:"expiry,omitempty"`
|
|
|
|
TriggeredAtOrigin string `json:"triggerOrigin,omitempty"`
|
2024-09-26 07:14:33 +00:00
|
|
|
GeneratorID string `json:"generatorId,omitempty"`
|
2023-08-15 12:47:05 +00:00
|
|
|
*AuthRequestInfo
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanOTPSMSCodeAddedEvent) Payload() interface{} {
|
2023-08-15 12:47:05 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanOTPSMSCodeAddedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-08-15 12:47:05 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *HumanOTPSMSCodeAddedEvent) SetBaseEvent(event *eventstore.BaseEvent) {
|
|
|
|
e.BaseEvent = *event
|
|
|
|
}
|
|
|
|
|
2023-10-13 14:45:38 +00:00
|
|
|
func (e *HumanOTPSMSCodeAddedEvent) TriggerOrigin() string {
|
|
|
|
return e.TriggeredAtOrigin
|
|
|
|
}
|
|
|
|
|
2023-08-15 12:47:05 +00:00
|
|
|
func NewHumanOTPSMSCodeAddedEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
code *crypto.CryptoValue,
|
|
|
|
expiry time.Duration,
|
|
|
|
info *AuthRequestInfo,
|
2024-09-26 07:14:33 +00:00
|
|
|
generatorID string,
|
2023-08-15 12:47:05 +00:00
|
|
|
) *HumanOTPSMSCodeAddedEvent {
|
|
|
|
return &HumanOTPSMSCodeAddedEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
HumanOTPSMSCodeAddedType,
|
|
|
|
),
|
2023-10-13 14:45:38 +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(),
|
2023-10-13 14:45:38 +00:00
|
|
|
AuthRequestInfo: info,
|
2024-09-26 07:14:33 +00:00
|
|
|
GeneratorID: generatorID,
|
2023-08-15 12:47:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type HumanOTPSMSCodeSentEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
2024-09-26 07:14:33 +00:00
|
|
|
GeneratorInfo *senders.CodeGeneratorInfo `json:"generatorInfo,omitempty"`
|
2023-08-15 12:47:05 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanOTPSMSCodeSentEvent) Payload() interface{} {
|
2023-08-15 12:47:05 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanOTPSMSCodeSentEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-08-15 12:47:05 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *HumanOTPSMSCodeSentEvent) SetBaseEvent(event *eventstore.BaseEvent) {
|
|
|
|
e.BaseEvent = *event
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewHumanOTPSMSCodeSentEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
2024-09-26 07:14:33 +00:00
|
|
|
generatorInfo *senders.CodeGeneratorInfo,
|
2023-08-15 12:47:05 +00:00
|
|
|
) *HumanOTPSMSCodeSentEvent {
|
|
|
|
return &HumanOTPSMSCodeSentEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
HumanOTPSMSCodeSentType,
|
|
|
|
),
|
2024-09-26 07:14:33 +00:00
|
|
|
GeneratorInfo: generatorInfo,
|
2023-08-15 12:47:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-02 16:57:53 +00:00
|
|
|
type HumanOTPSMSCheckSucceededEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
*AuthRequestInfo
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanOTPSMSCheckSucceededEvent) Payload() interface{} {
|
2023-08-02 16:57:53 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanOTPSMSCheckSucceededEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-08-02 16:57:53 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *HumanOTPSMSCheckSucceededEvent) SetBaseEvent(event *eventstore.BaseEvent) {
|
|
|
|
e.BaseEvent = *event
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewHumanOTPSMSCheckSucceededEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
info *AuthRequestInfo,
|
|
|
|
) *HumanOTPSMSCheckSucceededEvent {
|
|
|
|
return &HumanOTPSMSCheckSucceededEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
HumanOTPSMSCheckSucceededType,
|
|
|
|
),
|
|
|
|
AuthRequestInfo: info,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type HumanOTPSMSCheckFailedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
*AuthRequestInfo
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanOTPSMSCheckFailedEvent) Payload() interface{} {
|
2023-08-02 16:57:53 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanOTPSMSCheckFailedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-08-02 16:57:53 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *HumanOTPSMSCheckFailedEvent) SetBaseEvent(event *eventstore.BaseEvent) {
|
|
|
|
e.BaseEvent = *event
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewHumanOTPSMSCheckFailedEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
info *AuthRequestInfo,
|
|
|
|
) *HumanOTPSMSCheckFailedEvent {
|
|
|
|
return &HumanOTPSMSCheckFailedEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
HumanOTPSMSCheckFailedType,
|
|
|
|
),
|
|
|
|
AuthRequestInfo: info,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type HumanOTPEmailAddedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanOTPEmailAddedEvent) Payload() interface{} {
|
2023-08-02 16:57:53 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanOTPEmailAddedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-08-02 16:57:53 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *HumanOTPEmailAddedEvent) SetBaseEvent(event *eventstore.BaseEvent) {
|
|
|
|
e.BaseEvent = *event
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewHumanOTPEmailAddedEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
) *HumanOTPEmailAddedEvent {
|
|
|
|
return &HumanOTPEmailAddedEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
HumanOTPEmailAddedType,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type HumanOTPEmailRemovedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanOTPEmailRemovedEvent) Payload() interface{} {
|
2023-08-02 16:57:53 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanOTPEmailRemovedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-08-02 16:57:53 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *HumanOTPEmailRemovedEvent) SetBaseEvent(event *eventstore.BaseEvent) {
|
|
|
|
e.BaseEvent = *event
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewHumanOTPEmailRemovedEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
) *HumanOTPEmailRemovedEvent {
|
|
|
|
return &HumanOTPEmailRemovedEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
HumanOTPEmailRemovedType,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-15 12:47:05 +00:00
|
|
|
type HumanOTPEmailCodeAddedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
2023-10-13 14:45:38 +00:00
|
|
|
Code *crypto.CryptoValue `json:"code,omitempty"`
|
|
|
|
Expiry time.Duration `json:"expiry,omitempty"`
|
|
|
|
TriggeredAtOrigin string `json:"triggerOrigin,omitempty"`
|
2023-08-15 12:47:05 +00:00
|
|
|
*AuthRequestInfo
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanOTPEmailCodeAddedEvent) Payload() interface{} {
|
2023-08-15 12:47:05 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanOTPEmailCodeAddedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-08-15 12:47:05 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *HumanOTPEmailCodeAddedEvent) SetBaseEvent(event *eventstore.BaseEvent) {
|
|
|
|
e.BaseEvent = *event
|
|
|
|
}
|
|
|
|
|
2023-10-13 14:45:38 +00:00
|
|
|
func (e *HumanOTPEmailCodeAddedEvent) TriggerOrigin() string {
|
|
|
|
return e.TriggeredAtOrigin
|
|
|
|
}
|
|
|
|
|
2023-08-15 12:47:05 +00:00
|
|
|
func NewHumanOTPEmailCodeAddedEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
code *crypto.CryptoValue,
|
|
|
|
expiry time.Duration,
|
|
|
|
info *AuthRequestInfo,
|
|
|
|
) *HumanOTPEmailCodeAddedEvent {
|
|
|
|
return &HumanOTPEmailCodeAddedEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
HumanOTPEmailCodeAddedType,
|
|
|
|
),
|
2023-10-13 14:45:38 +00:00
|
|
|
Code: code,
|
|
|
|
Expiry: expiry,
|
|
|
|
AuthRequestInfo: info,
|
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(),
|
2023-08-15 12:47:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type HumanOTPEmailCodeSentEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
|
|
|
Code *crypto.CryptoValue `json:"code,omitempty"`
|
|
|
|
Expiry time.Duration `json:"expiry,omitempty"`
|
|
|
|
*AuthRequestInfo
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanOTPEmailCodeSentEvent) Payload() interface{} {
|
2023-08-15 12:47:05 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanOTPEmailCodeSentEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-08-15 12:47:05 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *HumanOTPEmailCodeSentEvent) SetBaseEvent(event *eventstore.BaseEvent) {
|
|
|
|
e.BaseEvent = *event
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewHumanOTPEmailCodeSentEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
) *HumanOTPEmailCodeSentEvent {
|
|
|
|
return &HumanOTPEmailCodeSentEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
HumanOTPEmailCodeSentType,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-02 16:57:53 +00:00
|
|
|
type HumanOTPEmailCheckSucceededEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
*AuthRequestInfo
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanOTPEmailCheckSucceededEvent) Payload() interface{} {
|
2023-08-02 16:57:53 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanOTPEmailCheckSucceededEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-08-02 16:57:53 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *HumanOTPEmailCheckSucceededEvent) SetBaseEvent(event *eventstore.BaseEvent) {
|
|
|
|
e.BaseEvent = *event
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewHumanOTPEmailCheckSucceededEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
info *AuthRequestInfo,
|
|
|
|
) *HumanOTPEmailCheckSucceededEvent {
|
|
|
|
return &HumanOTPEmailCheckSucceededEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
HumanOTPEmailCheckSucceededType,
|
|
|
|
),
|
|
|
|
AuthRequestInfo: info,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type HumanOTPEmailCheckFailedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
*AuthRequestInfo
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanOTPEmailCheckFailedEvent) Payload() interface{} {
|
2023-08-02 16:57:53 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *HumanOTPEmailCheckFailedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-08-02 16:57:53 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *HumanOTPEmailCheckFailedEvent) SetBaseEvent(event *eventstore.BaseEvent) {
|
|
|
|
e.BaseEvent = *event
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewHumanOTPEmailCheckFailedEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
info *AuthRequestInfo,
|
|
|
|
) *HumanOTPEmailCheckFailedEvent {
|
|
|
|
return &HumanOTPEmailCheckFailedEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
HumanOTPEmailCheckFailedType,
|
|
|
|
),
|
|
|
|
AuthRequestInfo: info,
|
|
|
|
}
|
|
|
|
}
|