From b96d15848493bdcf702ee6617f5fde0074607c3e Mon Sep 17 00:00:00 2001 From: Livio Amstutz Date: Wed, 7 Apr 2021 14:19:01 +0200 Subject: [PATCH] fix: pass necessary webauthn data through events (#1544) --- internal/command/user_human_webauthn.go | 11 ++++++++--- internal/command/user_human_webauthn_model.go | 10 +++++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/internal/command/user_human_webauthn.go b/internal/command/user_human_webauthn.go index d37407e00..e44fa3ff6 100644 --- a/internal/command/user_human_webauthn.go +++ b/internal/command/user_human_webauthn.go @@ -43,7 +43,7 @@ func (c *Commands) getHumanU2FLogin(ctx context.Context, userID, authReqID, reso if err != nil { return nil, err } - if tokenReadModel.State == domain.UserStateDeleted { + if tokenReadModel.State == domain.UserStateUnspecified || tokenReadModel.State == domain.UserStateDeleted { return nil, caos_errs.ThrowNotFound(nil, "COMMAND-5m88U", "Errors.User.NotFound") } return &domain.WebAuthNLogin{ @@ -62,11 +62,16 @@ func (c *Commands) getHumanPasswordlessLogin(ctx context.Context, userID, authRe if err != nil { return nil, err } - if tokenReadModel.State == domain.UserStateDeleted { + if tokenReadModel.State == domain.UserStateUnspecified || tokenReadModel.State == domain.UserStateDeleted { return nil, caos_errs.ThrowNotFound(nil, "COMMAND-fm84R", "Errors.User.NotFound") } return &domain.WebAuthNLogin{ - Challenge: tokenReadModel.Challenge, + ObjectRoot: models.ObjectRoot{ + AggregateID: tokenReadModel.AggregateID, + }, + Challenge: tokenReadModel.Challenge, + AllowedCredentialIDs: tokenReadModel.AllowedCredentialIDs, + UserVerification: tokenReadModel.UserVerification, }, nil } diff --git a/internal/command/user_human_webauthn_model.go b/internal/command/user_human_webauthn_model.go index 1ebdabd08..26686008e 100644 --- a/internal/command/user_human_webauthn_model.go +++ b/internal/command/user_human_webauthn_model.go @@ -361,9 +361,11 @@ func (rm *HumanU2FLoginReadModel) Query() *eventstore.SearchQueryBuilder { type HumanPasswordlessLoginReadModel struct { eventstore.WriteModel - AuthReqID string - Challenge string - State domain.UserState + AuthReqID string + Challenge string + AllowedCredentialIDs [][]byte + UserVerification domain.UserVerificationRequirement + State domain.UserState } func NewHumanPasswordlessLoginReadModel(userID, authReqID, resourceOwner string) *HumanPasswordlessLoginReadModel { @@ -395,6 +397,8 @@ func (wm *HumanPasswordlessLoginReadModel) Reduce() error { switch e := event.(type) { case *user.HumanPasswordlessBeginLoginEvent: wm.Challenge = e.Challenge + wm.AllowedCredentialIDs = e.AllowedCredentialIDs + wm.UserVerification = e.UserVerification wm.State = domain.UserStateActive case *user.UserRemovedEvent: wm.State = domain.UserStateDeleted