2021-01-04 13:52:13 +00:00
|
|
|
package user
|
2020-12-10 15:18:52 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2021-03-22 13:40:25 +00:00
|
|
|
|
2021-02-23 14:13:04 +00:00
|
|
|
"github.com/caos/zitadel/internal/domain"
|
2020-12-10 15:18:52 +00:00
|
|
|
"github.com/caos/zitadel/internal/errors"
|
2021-02-23 14:13:04 +00:00
|
|
|
"github.com/caos/zitadel/internal/eventstore"
|
|
|
|
"github.com/caos/zitadel/internal/eventstore/repository"
|
2020-12-10 15:18:52 +00:00
|
|
|
)
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
type HumanWebAuthNAddedEvent struct {
|
2020-12-10 15:18:52 +00:00
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
2021-01-15 08:32:59 +00:00
|
|
|
WebAuthNTokenID string `json:"webAuthNTokenId"`
|
|
|
|
Challenge string `json:"challenge"`
|
2020-12-10 15:18:52 +00:00
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
func (e *HumanWebAuthNAddedEvent) Data() interface{} {
|
2020-12-10 15:18:52 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2021-01-21 09:49:38 +00:00
|
|
|
func (e *HumanWebAuthNAddedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-02-08 10:30:30 +00:00
|
|
|
func NewHumanWebAuthNAddedEvent(
|
|
|
|
base *eventstore.BaseEvent,
|
2020-12-10 15:18:52 +00:00
|
|
|
webAuthNTokenID,
|
|
|
|
challenge string,
|
2021-01-04 13:52:13 +00:00
|
|
|
) *HumanWebAuthNAddedEvent {
|
|
|
|
return &HumanWebAuthNAddedEvent{
|
2021-02-08 10:30:30 +00:00
|
|
|
BaseEvent: *base,
|
2020-12-10 15:18:52 +00:00
|
|
|
WebAuthNTokenID: webAuthNTokenID,
|
|
|
|
Challenge: challenge,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-03 08:19:07 +00:00
|
|
|
func HumanWebAuthNAddedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
2021-01-04 13:52:13 +00:00
|
|
|
webAuthNAdded := &HumanWebAuthNAddedEvent{
|
2020-12-10 15:18:52 +00:00
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
|
|
|
err := json.Unmarshal(event.Data, webAuthNAdded)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.ThrowInternal(err, "USER-tB8sf", "unable to unmarshal human webAuthN added")
|
|
|
|
}
|
|
|
|
return webAuthNAdded, nil
|
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
type HumanWebAuthNVerifiedEvent struct {
|
2020-12-10 15:18:52 +00:00
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
2021-01-15 08:32:59 +00:00
|
|
|
WebAuthNTokenID string `json:"webAuthNTokenId"`
|
|
|
|
KeyID []byte `json:"keyId"`
|
|
|
|
PublicKey []byte `json:"publicKey"`
|
|
|
|
AttestationType string `json:"attestationType"`
|
|
|
|
AAGUID []byte `json:"aaguid"`
|
|
|
|
SignCount uint32 `json:"signCount"`
|
|
|
|
WebAuthNTokenName string `json:"webAuthNTokenName"`
|
2021-03-22 13:40:25 +00:00
|
|
|
UserAgentID string `json:"userAgentID,omitempty"`
|
2020-12-10 15:18:52 +00:00
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
func (e *HumanWebAuthNVerifiedEvent) Data() interface{} {
|
2020-12-10 15:18:52 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2021-01-21 09:49:38 +00:00
|
|
|
func (e *HumanWebAuthNVerifiedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-02-08 10:30:30 +00:00
|
|
|
func NewHumanWebAuthNVerifiedEvent(
|
|
|
|
base *eventstore.BaseEvent,
|
2020-12-10 15:18:52 +00:00
|
|
|
webAuthNTokenID,
|
|
|
|
webAuthNTokenName,
|
|
|
|
attestationType string,
|
|
|
|
keyID,
|
|
|
|
publicKey,
|
|
|
|
aaguid []byte,
|
|
|
|
signCount uint32,
|
2021-03-22 13:40:25 +00:00
|
|
|
userAgentID string,
|
2021-01-04 13:52:13 +00:00
|
|
|
) *HumanWebAuthNVerifiedEvent {
|
|
|
|
return &HumanWebAuthNVerifiedEvent{
|
2021-02-08 10:30:30 +00:00
|
|
|
BaseEvent: *base,
|
2020-12-10 15:18:52 +00:00
|
|
|
WebAuthNTokenID: webAuthNTokenID,
|
|
|
|
KeyID: keyID,
|
|
|
|
PublicKey: publicKey,
|
|
|
|
AttestationType: attestationType,
|
|
|
|
AAGUID: aaguid,
|
|
|
|
SignCount: signCount,
|
|
|
|
WebAuthNTokenName: webAuthNTokenName,
|
2021-03-22 13:40:25 +00:00
|
|
|
UserAgentID: userAgentID,
|
2020-12-10 15:18:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-03 08:19:07 +00:00
|
|
|
func HumanWebAuthNVerifiedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
2021-01-04 13:52:13 +00:00
|
|
|
webauthNVerified := &HumanWebAuthNVerifiedEvent{
|
2020-12-10 15:18:52 +00:00
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
|
|
|
err := json.Unmarshal(event.Data, webauthNVerified)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.ThrowInternal(err, "USER-B0zDs", "unable to unmarshal human webAuthN verified")
|
|
|
|
}
|
|
|
|
return webauthNVerified, nil
|
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
type HumanWebAuthNSignCountChangedEvent struct {
|
2020-12-10 15:18:52 +00:00
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
2021-01-15 08:32:59 +00:00
|
|
|
WebAuthNTokenID string `json:"webAuthNTokenId"`
|
|
|
|
SignCount uint32 `json:"signCount"`
|
2020-12-10 15:18:52 +00:00
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
func (e *HumanWebAuthNSignCountChangedEvent) Data() interface{} {
|
2020-12-10 15:18:52 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2021-01-21 09:49:38 +00:00
|
|
|
func (e *HumanWebAuthNSignCountChangedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-02-08 10:30:30 +00:00
|
|
|
func NewHumanWebAuthNSignCountChangedEvent(
|
|
|
|
base *eventstore.BaseEvent,
|
2020-12-10 15:18:52 +00:00
|
|
|
webAuthNTokenID string,
|
|
|
|
signCount uint32,
|
2021-01-04 13:52:13 +00:00
|
|
|
) *HumanWebAuthNSignCountChangedEvent {
|
|
|
|
return &HumanWebAuthNSignCountChangedEvent{
|
2021-02-08 10:30:30 +00:00
|
|
|
BaseEvent: *base,
|
2020-12-10 15:18:52 +00:00
|
|
|
WebAuthNTokenID: webAuthNTokenID,
|
|
|
|
SignCount: signCount,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-03 08:19:07 +00:00
|
|
|
func HumanWebAuthNSignCountChangedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
2021-01-04 13:52:13 +00:00
|
|
|
webauthNVerified := &HumanWebAuthNSignCountChangedEvent{
|
2020-12-10 15:18:52 +00:00
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
|
|
|
err := json.Unmarshal(event.Data, webauthNVerified)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.ThrowInternal(err, "USER-5Gm0s", "unable to unmarshal human webAuthN sign count")
|
|
|
|
}
|
|
|
|
return webauthNVerified, nil
|
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
type HumanWebAuthNRemovedEvent struct {
|
2020-12-10 15:18:52 +00:00
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
WebAuthNTokenID string `json:"webAuthNTokenId"`
|
|
|
|
State domain.MFAState `json:"-"`
|
2020-12-10 15:18:52 +00:00
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
func (e *HumanWebAuthNRemovedEvent) Data() interface{} {
|
2020-12-10 15:18:52 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2021-01-21 09:49:38 +00:00
|
|
|
func (e *HumanWebAuthNRemovedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-02-08 10:30:30 +00:00
|
|
|
func NewHumanWebAuthNRemovedEvent(
|
|
|
|
base *eventstore.BaseEvent,
|
2020-12-10 15:18:52 +00:00
|
|
|
webAuthNTokenID string,
|
2021-01-04 13:52:13 +00:00
|
|
|
) *HumanWebAuthNRemovedEvent {
|
|
|
|
return &HumanWebAuthNRemovedEvent{
|
2021-02-08 10:30:30 +00:00
|
|
|
BaseEvent: *base,
|
2020-12-10 15:18:52 +00:00
|
|
|
WebAuthNTokenID: webAuthNTokenID,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-03 08:19:07 +00:00
|
|
|
func HumanWebAuthNRemovedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
2021-01-04 13:52:13 +00:00
|
|
|
webauthNVerified := &HumanWebAuthNRemovedEvent{
|
2020-12-10 15:18:52 +00:00
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
|
|
|
err := json.Unmarshal(event.Data, webauthNVerified)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.ThrowInternal(err, "USER-gM9sd", "unable to unmarshal human webAuthN token removed")
|
|
|
|
}
|
|
|
|
return webauthNVerified, nil
|
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
type HumanWebAuthNBeginLoginEvent struct {
|
2020-12-10 15:18:52 +00:00
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
2021-04-07 10:56:59 +00:00
|
|
|
Challenge string `json:"challenge"`
|
|
|
|
AllowedCredentialIDs [][]byte `json:"allowedCredentialIDs"`
|
|
|
|
UserVerification domain.UserVerificationRequirement `json:"userVerification"`
|
2021-02-08 10:30:30 +00:00
|
|
|
*AuthRequestInfo
|
2020-12-10 15:18:52 +00:00
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
func (e *HumanWebAuthNBeginLoginEvent) Data() interface{} {
|
2020-12-10 15:18:52 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2021-01-21 09:49:38 +00:00
|
|
|
func (e *HumanWebAuthNBeginLoginEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-04-07 10:56:59 +00:00
|
|
|
func NewHumanWebAuthNBeginLoginEvent(base *eventstore.BaseEvent, challenge string, allowedCredentialIDs [][]byte, userVerification domain.UserVerificationRequirement, info *AuthRequestInfo) *HumanWebAuthNBeginLoginEvent {
|
2021-01-04 13:52:13 +00:00
|
|
|
return &HumanWebAuthNBeginLoginEvent{
|
2021-04-07 10:56:59 +00:00
|
|
|
BaseEvent: *base,
|
|
|
|
Challenge: challenge,
|
|
|
|
AllowedCredentialIDs: allowedCredentialIDs,
|
|
|
|
UserVerification: userVerification,
|
|
|
|
AuthRequestInfo: info,
|
2020-12-10 15:18:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-03 08:19:07 +00:00
|
|
|
func HumanWebAuthNBeginLoginEventMapper(event *repository.Event) (eventstore.Event, error) {
|
2021-01-04 13:52:13 +00:00
|
|
|
webAuthNAdded := &HumanWebAuthNBeginLoginEvent{
|
2020-12-10 15:18:52 +00:00
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
|
|
|
err := json.Unmarshal(event.Data, webAuthNAdded)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.ThrowInternal(err, "USER-rMb8x", "unable to unmarshal human webAuthN begin login")
|
|
|
|
}
|
|
|
|
return webAuthNAdded, nil
|
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
type HumanWebAuthNCheckSucceededEvent struct {
|
2020-12-10 15:18:52 +00:00
|
|
|
eventstore.BaseEvent `json:"-"`
|
2021-03-01 07:48:50 +00:00
|
|
|
*AuthRequestInfo
|
2020-12-10 15:18:52 +00:00
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
func (e *HumanWebAuthNCheckSucceededEvent) Data() interface{} {
|
2020-12-10 15:18:52 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2021-01-21 09:49:38 +00:00
|
|
|
func (e *HumanWebAuthNCheckSucceededEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-03-01 07:48:50 +00:00
|
|
|
func NewHumanWebAuthNCheckSucceededEvent(
|
|
|
|
base *eventstore.BaseEvent,
|
|
|
|
info *AuthRequestInfo) *HumanWebAuthNCheckSucceededEvent {
|
2021-01-04 13:52:13 +00:00
|
|
|
return &HumanWebAuthNCheckSucceededEvent{
|
2021-03-01 07:48:50 +00:00
|
|
|
BaseEvent: *base,
|
|
|
|
AuthRequestInfo: info,
|
2020-12-10 15:18:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-03 08:19:07 +00:00
|
|
|
func HumanWebAuthNCheckSucceededEventMapper(event *repository.Event) (eventstore.Event, error) {
|
2021-01-04 13:52:13 +00:00
|
|
|
webAuthNAdded := &HumanWebAuthNCheckSucceededEvent{
|
2020-12-10 15:18:52 +00:00
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
|
|
|
err := json.Unmarshal(event.Data, webAuthNAdded)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.ThrowInternal(err, "USER-2M0fg", "unable to unmarshal human webAuthN check succeeded")
|
|
|
|
}
|
|
|
|
return webAuthNAdded, nil
|
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
type HumanWebAuthNCheckFailedEvent struct {
|
2020-12-10 15:18:52 +00:00
|
|
|
eventstore.BaseEvent `json:"-"`
|
2021-03-01 07:48:50 +00:00
|
|
|
*AuthRequestInfo
|
2020-12-10 15:18:52 +00:00
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
func (e *HumanWebAuthNCheckFailedEvent) Data() interface{} {
|
2020-12-10 15:18:52 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2021-01-21 09:49:38 +00:00
|
|
|
func (e *HumanWebAuthNCheckFailedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-03-01 07:48:50 +00:00
|
|
|
func NewHumanWebAuthNCheckFailedEvent(
|
|
|
|
base *eventstore.BaseEvent,
|
|
|
|
info *AuthRequestInfo) *HumanWebAuthNCheckFailedEvent {
|
2021-01-04 13:52:13 +00:00
|
|
|
return &HumanWebAuthNCheckFailedEvent{
|
2021-03-01 07:48:50 +00:00
|
|
|
BaseEvent: *base,
|
|
|
|
AuthRequestInfo: info,
|
2020-12-10 15:18:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-03 08:19:07 +00:00
|
|
|
func HumanWebAuthNCheckFailedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
2021-01-04 13:52:13 +00:00
|
|
|
webAuthNAdded := &HumanWebAuthNCheckFailedEvent{
|
2020-12-10 15:18:52 +00:00
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
|
|
|
err := json.Unmarshal(event.Data, webAuthNAdded)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.ThrowInternal(err, "USER-O0dse", "unable to unmarshal human webAuthN check failed")
|
|
|
|
}
|
|
|
|
return webAuthNAdded, nil
|
|
|
|
}
|