mirror of
https://github.com/zitadel/zitadel.git
synced 2025-04-25 22:30:51 +00:00

* 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>
104 lines
2.8 KiB
Go
104 lines
2.8 KiB
Go
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/caos/zitadel/internal/auth_request/model"
|
|
caos_errs "github.com/caos/zitadel/internal/errors"
|
|
)
|
|
|
|
const (
|
|
tmplMFAPrompt = "mfaprompt"
|
|
)
|
|
|
|
type mfaPromptData struct {
|
|
MFAProvider model.MFAType `schema:"provider"`
|
|
Skip bool `schema:"skip"`
|
|
}
|
|
|
|
func (l *Login) handleMFAPrompt(w http.ResponseWriter, r *http.Request) {
|
|
data := new(mfaPromptData)
|
|
authReq, err := l.getAuthRequestAndParseData(r, data)
|
|
if err != nil {
|
|
l.renderError(w, r, authReq, err)
|
|
return
|
|
}
|
|
if !data.Skip {
|
|
mfaVerifyData := new(mfaVerifyData)
|
|
mfaVerifyData.MFAType = data.MFAProvider
|
|
l.handleMFACreation(w, r, authReq, mfaVerifyData)
|
|
return
|
|
}
|
|
err = l.authRepo.SkipMFAInit(setContext(r.Context(), authReq.UserOrgID), authReq.UserID)
|
|
if err != nil {
|
|
l.renderError(w, r, authReq, err)
|
|
return
|
|
}
|
|
l.handleLogin(w, r)
|
|
}
|
|
|
|
func (l *Login) handleMFAPromptSelection(w http.ResponseWriter, r *http.Request) {
|
|
data := new(mfaPromptData)
|
|
authReq, err := l.getAuthRequestAndParseData(r, data)
|
|
if err != nil {
|
|
l.renderError(w, r, authReq, err)
|
|
return
|
|
}
|
|
|
|
l.renderNextStep(w, r, authReq)
|
|
}
|
|
|
|
func (l *Login) renderMFAPrompt(w http.ResponseWriter, r *http.Request, authReq *model.AuthRequest, mfaPromptData *model.MFAPromptStep, err error) {
|
|
var errType, errMessage string
|
|
if err != nil {
|
|
errMessage = l.getErrorMessage(r, err)
|
|
}
|
|
data := mfaData{
|
|
baseData: l.getBaseData(r, authReq, "MFA Prompt", errType, errMessage),
|
|
profileData: l.getProfileData(authReq),
|
|
}
|
|
|
|
if mfaPromptData == nil {
|
|
l.renderError(w, r, authReq, caos_errs.ThrowPreconditionFailed(nil, "APP-XU0tj", "Errors.User.MFA.NoProviders"))
|
|
return
|
|
}
|
|
|
|
data.MFAProviders = mfaPromptData.MFAProviders
|
|
data.MFARequired = mfaPromptData.Required
|
|
|
|
if len(mfaPromptData.MFAProviders) == 1 && mfaPromptData.Required {
|
|
data := &mfaVerifyData{
|
|
MFAType: mfaPromptData.MFAProviders[0],
|
|
}
|
|
l.handleMFACreation(w, r, authReq, data)
|
|
return
|
|
}
|
|
l.renderer.RenderTemplate(w, r, l.renderer.Templates[tmplMFAPrompt], data, nil)
|
|
}
|
|
|
|
func (l *Login) handleMFACreation(w http.ResponseWriter, r *http.Request, authReq *model.AuthRequest, data *mfaVerifyData) {
|
|
switch data.MFAType {
|
|
case model.MFATypeOTP:
|
|
l.handleOTPCreation(w, r, authReq, data)
|
|
return
|
|
case model.MFATypeU2F:
|
|
l.renderRegisterU2F(w, r, authReq, nil)
|
|
return
|
|
}
|
|
l.renderError(w, r, authReq, caos_errs.ThrowPreconditionFailed(nil, "APP-Or3HO", "Errors.User.MFA.NoProviders"))
|
|
}
|
|
|
|
func (l *Login) handleOTPCreation(w http.ResponseWriter, r *http.Request, authReq *model.AuthRequest, data *mfaVerifyData) {
|
|
otp, err := l.authRepo.AddMFAOTP(setContext(r.Context(), authReq.UserOrgID), authReq.UserID)
|
|
if err != nil {
|
|
l.renderError(w, r, authReq, err)
|
|
return
|
|
}
|
|
|
|
data.otpData = otpData{
|
|
Secret: otp.SecretString,
|
|
Url: otp.Url,
|
|
}
|
|
l.renderMFAInitVerify(w, r, authReq, data, nil)
|
|
}
|