mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 04:57:33 +00:00
feat: add WebAuthN support for passwordless login and 2fa (#966)
* at least registration prompt works * in memory test for login * buttons to start webauthn process * begin eventstore impl * begin eventstore impl * serialize into bytes * fix: u2f, passwordless types * fix for localhost * fix script * fix: u2f, passwordless types * fix: add u2f * fix: verify u2f * fix: session data in event store * fix: u2f credentials in eventstore * fix: webauthn pkg handles business models * feat: tests * feat: append events * fix: test * fix: check only ready webauthn creds * fix: move u2f methods to authrepo * frontend improvements * fix return * feat: add passwordless * feat: add passwordless * improve ui / error handling * separate call for login * fix login * js * feat: u2f login methods * feat: remove unused session id * feat: error handling * feat: error handling * feat: refactor user eventstore * feat: finish webauthn * feat: u2f and passwordlss in auth.proto * u2f step * passwordless step * cleanup js * EndpointPasswordLessLogin * migration * update mfaChecked test * next step test * token name * cleanup * attribute * passwordless as tokens * remove sms as otp type * add "user" to amr for webauthn * error handling * fixes * fix tests * naming * naming * fixes * session handler * i18n * error handling in login * Update internal/ui/login/static/i18n/de.yaml Co-authored-by: Fabi <38692350+fgerschwiler@users.noreply.github.com> * Update internal/ui/login/static/i18n/en.yaml Co-authored-by: Fabi <38692350+fgerschwiler@users.noreply.github.com> * improvements * merge fixes * fixes * fixes Co-authored-by: Fabiennne <fabienne.gerschwiler@gmail.com> Co-authored-by: Fabi <38692350+fgerschwiler@users.noreply.github.com>
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
iam_model "github.com/caos/zitadel/internal/iam/model"
|
||||
"time"
|
||||
|
||||
"golang.org/x/text/language"
|
||||
|
||||
req_model "github.com/caos/zitadel/internal/auth_request/model"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore/models"
|
||||
iam_model "github.com/caos/zitadel/internal/iam/model"
|
||||
"github.com/caos/zitadel/internal/model"
|
||||
"golang.org/x/text/language"
|
||||
)
|
||||
|
||||
type UserView struct {
|
||||
@@ -46,12 +47,20 @@ type HumanView struct {
|
||||
PostalCode string
|
||||
Region string
|
||||
StreetAddress string
|
||||
OTPState MfaState
|
||||
MfaMaxSetUp req_model.MFALevel
|
||||
MfaInitSkipped time.Time
|
||||
OTPState MFAState
|
||||
U2FTokens []*WebAuthNView
|
||||
PasswordlessTokens []*WebAuthNView
|
||||
MFAMaxSetUp req_model.MFALevel
|
||||
MFAInitSkipped time.Time
|
||||
InitRequired bool
|
||||
}
|
||||
|
||||
type WebAuthNView struct {
|
||||
TokenID string
|
||||
Name string
|
||||
State MFAState
|
||||
}
|
||||
|
||||
type MachineView struct {
|
||||
LastKeyAdded time.Time
|
||||
Name string
|
||||
@@ -108,7 +117,7 @@ func (r *UserSearchRequest) AppendMyOrgQuery(orgID string) {
|
||||
r.Queries = append(r.Queries, &UserSearchQuery{Key: UserSearchKeyResourceOwner, Method: model.SearchMethodEquals, Value: orgID})
|
||||
}
|
||||
|
||||
func (u *UserView) MfaTypesSetupPossible(level req_model.MFALevel, policy *iam_model.LoginPolicyView) []req_model.MFAType {
|
||||
func (u *UserView) MFATypesSetupPossible(level req_model.MFALevel, policy *iam_model.LoginPolicyView) []req_model.MFAType {
|
||||
types := make([]req_model.MFAType, 0)
|
||||
switch level {
|
||||
default:
|
||||
@@ -118,13 +127,14 @@ func (u *UserView) MfaTypesSetupPossible(level req_model.MFALevel, policy *iam_m
|
||||
for _, mfaType := range policy.SecondFactors {
|
||||
switch mfaType {
|
||||
case iam_model.SecondFactorTypeOTP:
|
||||
if u.OTPState != MfaStateReady {
|
||||
if u.OTPState != MFAStateReady {
|
||||
types = append(types, req_model.MFATypeOTP)
|
||||
}
|
||||
case iam_model.SecondFactorTypeU2F:
|
||||
types = append(types, req_model.MFATypeU2F)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//PLANNED: add sms
|
||||
fallthrough
|
||||
case req_model.MFALevelMultiFactor:
|
||||
@@ -132,17 +142,15 @@ func (u *UserView) MfaTypesSetupPossible(level req_model.MFALevel, policy *iam_m
|
||||
for _, mfaType := range policy.MultiFactors {
|
||||
switch mfaType {
|
||||
case iam_model.MultiFactorTypeU2FWithPIN:
|
||||
// TODO: Check if not set up already
|
||||
// types = append(types, req_model.MFATypeU2F)
|
||||
types = append(types, req_model.MFATypeU2FUserVerification)
|
||||
}
|
||||
}
|
||||
}
|
||||
//PLANNED: add token
|
||||
}
|
||||
return types
|
||||
}
|
||||
|
||||
func (u *UserView) MfaTypesAllowed(level req_model.MFALevel, policy *iam_model.LoginPolicyView) ([]req_model.MFAType, bool) {
|
||||
func (u *UserView) MFATypesAllowed(level req_model.MFALevel, policy *iam_model.LoginPolicyView) ([]req_model.MFAType, bool) {
|
||||
types := make([]req_model.MFAType, 0)
|
||||
required := true
|
||||
switch level {
|
||||
@@ -154,9 +162,13 @@ func (u *UserView) MfaTypesAllowed(level req_model.MFALevel, policy *iam_model.L
|
||||
for _, mfaType := range policy.SecondFactors {
|
||||
switch mfaType {
|
||||
case iam_model.SecondFactorTypeOTP:
|
||||
if u.OTPState == MfaStateReady {
|
||||
if u.OTPState == MFAStateReady {
|
||||
types = append(types, req_model.MFATypeOTP)
|
||||
}
|
||||
case iam_model.SecondFactorTypeU2F:
|
||||
if u.IsU2FReady() {
|
||||
types = append(types, req_model.MFATypeU2F)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -167,8 +179,9 @@ func (u *UserView) MfaTypesAllowed(level req_model.MFALevel, policy *iam_model.L
|
||||
for _, mfaType := range policy.MultiFactors {
|
||||
switch mfaType {
|
||||
case iam_model.MultiFactorTypeU2FWithPIN:
|
||||
// TODO: Check if not set up already
|
||||
// types = append(types, req_model.MFATypeU2F)
|
||||
if u.IsPasswordlessReady() {
|
||||
types = append(types, req_model.MFATypeU2FUserVerification)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -177,15 +190,33 @@ func (u *UserView) MfaTypesAllowed(level req_model.MFALevel, policy *iam_model.L
|
||||
return types, required
|
||||
}
|
||||
|
||||
func (u *UserView) IsU2FReady() bool {
|
||||
for _, token := range u.U2FTokens {
|
||||
if token.State == MFAStateReady {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (u *UserView) IsPasswordlessReady() bool {
|
||||
for _, token := range u.PasswordlessTokens {
|
||||
if token.State == MFAStateReady {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (u *UserView) HasRequiredOrgMFALevel(policy *iam_model.LoginPolicyView) bool {
|
||||
if !policy.ForceMFA {
|
||||
return true
|
||||
}
|
||||
switch u.MfaMaxSetUp {
|
||||
switch u.MFAMaxSetUp {
|
||||
case req_model.MFALevelSecondFactor:
|
||||
return policy.HasSecondFactors()
|
||||
case req_model.MFALevelMultiFactor:
|
||||
return true
|
||||
return policy.HasMultiFactors()
|
||||
default:
|
||||
return false
|
||||
}
|
||||
|
Reference in New Issue
Block a user