zitadel/internal/v2/repository/user/human_mfa_u2f.go
Fabi 320679467b
feat: User login commands (#1228)
* feat: change login to command side

* feat: change login to command side

* fix: fix push on user

* feat: user command side

* feat: sign out

* feat: command side login

* feat: command side login

* feat: fix register user

* feat: fix register user

* feat: fix web auth n events

* feat: add machine keys

* feat: send codes

* feat: move authrequest to domain

* feat: move authrequest to domain

* feat: webauthn working

* feat: external users

* feat: external users login

* feat: notify users

* fix: tests

* feat: cascade remove user grants on project remove

* fix: webauthn

* fix: pr requests

* fix: register human with member

* fix: fix bugs

* fix: fix bugs
2021-02-08 11:30:30 +01:00

225 lines
5.6 KiB
Go

package user
import (
"context"
"github.com/caos/zitadel/internal/eventstore/v2"
"github.com/caos/zitadel/internal/eventstore/v2/repository"
)
const (
u2fEventPrefix = mfaEventPrefix + "u2f.token."
HumanU2FTokenAddedType = u2fEventPrefix + "added"
HumanU2FTokenVerifiedType = u2fEventPrefix + "verified"
HumanU2FTokenSignCountChangedType = u2fEventPrefix + "signcount.changed"
HumanU2FTokenRemovedType = u2fEventPrefix + "removed"
HumanU2FTokenBeginLoginType = u2fEventPrefix + "begin.login"
HumanU2FTokenCheckSucceededType = u2fEventPrefix + "check.succeeded"
HumanU2FTokenCheckFailedType = u2fEventPrefix + "check.failed"
)
type HumanU2FAddedEvent struct {
HumanWebAuthNAddedEvent
}
func NewHumanU2FAddedEvent(
ctx context.Context,
webAuthNTokenID,
challenge string,
) *HumanU2FAddedEvent {
return &HumanU2FAddedEvent{
HumanWebAuthNAddedEvent: *NewHumanWebAuthNAddedEvent(
eventstore.NewBaseEventForPush(
ctx,
HumanU2FTokenAddedType,
),
webAuthNTokenID,
challenge,
),
}
}
func HumanU2FAddedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
e, err := HumanWebAuthNAddedEventMapper(event)
if err != nil {
return nil, err
}
return &HumanU2FAddedEvent{HumanWebAuthNAddedEvent: *e.(*HumanWebAuthNAddedEvent)}, nil
}
type HumanU2FVerifiedEvent struct {
HumanWebAuthNVerifiedEvent
}
func NewHumanU2FVerifiedEvent(
ctx context.Context,
webAuthNTokenID,
webAuthNTokenName,
attestationType string,
keyID,
publicKey,
aaguid []byte,
signCount uint32,
) *HumanU2FVerifiedEvent {
return &HumanU2FVerifiedEvent{
HumanWebAuthNVerifiedEvent: *NewHumanWebAuthNVerifiedEvent(
eventstore.NewBaseEventForPush(
ctx,
HumanU2FTokenVerifiedType,
),
webAuthNTokenID,
webAuthNTokenName,
attestationType,
keyID,
publicKey,
aaguid,
signCount,
),
}
}
func HumanU2FVerifiedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
e, err := HumanWebAuthNVerifiedEventMapper(event)
if err != nil {
return nil, err
}
return &HumanU2FVerifiedEvent{HumanWebAuthNVerifiedEvent: *e.(*HumanWebAuthNVerifiedEvent)}, nil
}
type HumanU2FSignCountChangedEvent struct {
HumanWebAuthNSignCountChangedEvent
}
func NewHumanU2FSignCountChangedEvent(
ctx context.Context,
webAuthNTokenID string,
signCount uint32,
) *HumanU2FSignCountChangedEvent {
return &HumanU2FSignCountChangedEvent{
HumanWebAuthNSignCountChangedEvent: *NewHumanWebAuthNSignCountChangedEvent(
eventstore.NewBaseEventForPush(
ctx,
HumanU2FTokenSignCountChangedType,
),
webAuthNTokenID,
signCount,
),
}
}
func HumanU2FSignCountChangedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
e, err := HumanWebAuthNSignCountChangedEventMapper(event)
if err != nil {
return nil, err
}
return &HumanU2FSignCountChangedEvent{HumanWebAuthNSignCountChangedEvent: *e.(*HumanWebAuthNSignCountChangedEvent)}, nil
}
type HumanU2FRemovedEvent struct {
HumanWebAuthNRemovedEvent
}
func NewHumanU2FRemovedEvent(
ctx context.Context,
webAuthNTokenID string,
) *HumanU2FRemovedEvent {
return &HumanU2FRemovedEvent{
HumanWebAuthNRemovedEvent: *NewHumanWebAuthNRemovedEvent(
eventstore.NewBaseEventForPush(
ctx,
HumanU2FTokenRemovedType,
),
webAuthNTokenID,
),
}
}
func HumanU2FRemovedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
e, err := HumanWebAuthNRemovedEventMapper(event)
if err != nil {
return nil, err
}
return &HumanU2FRemovedEvent{HumanWebAuthNRemovedEvent: *e.(*HumanWebAuthNRemovedEvent)}, nil
}
type HumanU2FBeginLoginEvent struct {
HumanWebAuthNBeginLoginEvent
}
func NewHumanU2FBeginLoginEvent(
ctx context.Context,
challenge string,
info *AuthRequestInfo,
) *HumanU2FBeginLoginEvent {
return &HumanU2FBeginLoginEvent{
HumanWebAuthNBeginLoginEvent: *NewHumanWebAuthNBeginLoginEvent(
eventstore.NewBaseEventForPush(
ctx,
HumanU2FTokenVerifiedType,
),
challenge,
info,
),
}
}
func HumanU2FBeginLoginEventMapper(event *repository.Event) (eventstore.EventReader, error) {
e, err := HumanWebAuthNBeginLoginEventMapper(event)
if err != nil {
return nil, err
}
return &HumanU2FBeginLoginEvent{HumanWebAuthNBeginLoginEvent: *e.(*HumanWebAuthNBeginLoginEvent)}, nil
}
type HumanU2FCheckSucceededEvent struct {
HumanWebAuthNCheckSucceededEvent
}
func NewHumanU2FCheckSucceededEvent(ctx context.Context) *HumanU2FCheckSucceededEvent {
return &HumanU2FCheckSucceededEvent{
HumanWebAuthNCheckSucceededEvent: *NewHumanWebAuthNCheckSucceededEvent(
eventstore.NewBaseEventForPush(
ctx,
HumanU2FTokenCheckSucceededType,
),
),
}
}
func HumanU2FCheckSucceededEventMapper(event *repository.Event) (eventstore.EventReader, error) {
e, err := HumanWebAuthNCheckSucceededEventMapper(event)
if err != nil {
return nil, err
}
return &HumanU2FCheckSucceededEvent{HumanWebAuthNCheckSucceededEvent: *e.(*HumanWebAuthNCheckSucceededEvent)}, nil
}
type HumanU2FCheckFailedEvent struct {
HumanWebAuthNCheckFailedEvent
}
func NewHumanU2FCheckFailedEvent(ctx context.Context) *HumanU2FCheckFailedEvent {
return &HumanU2FCheckFailedEvent{
HumanWebAuthNCheckFailedEvent: *NewHumanWebAuthNCheckFailedEvent(
eventstore.NewBaseEventForPush(
ctx,
HumanU2FTokenCheckFailedType,
),
),
}
}
func HumanU2FCheckFailedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
e, err := HumanWebAuthNCheckFailedEventMapper(event)
if err != nil {
return nil, err
}
return &HumanU2FCheckFailedEvent{HumanWebAuthNCheckFailedEvent: *e.(*HumanWebAuthNCheckFailedEvent)}, nil
}