mirror of
https://github.com/zitadel/zitadel.git
synced 2025-04-16 02:41:29 +00:00

* fix: typo ZITADEL uppercase for OTP Issuer * fix: password validation after change in current user agent * fix: otp validation after setup in current user agent * add waiting * add waiting * show u2f state * regenerate css * add useragentID to webauthn verify * return mfa attribute in mgmt * switch between providers * use preferredLoginName for webauthn display * some fixes * correct translations for login * add some missing event translations * fix usersession test * remove unnecessary cancel button on password change done
66 lines
1.8 KiB
Go
66 lines
1.8 KiB
Go
package handler
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"net/http"
|
|
|
|
http_mw "github.com/caos/zitadel/internal/api/http/middleware"
|
|
"github.com/caos/zitadel/internal/auth_request/model"
|
|
user_model "github.com/caos/zitadel/internal/user/model"
|
|
)
|
|
|
|
const (
|
|
tmplMFAU2FInit = "mfainitu2f"
|
|
)
|
|
|
|
type u2fInitData struct {
|
|
webAuthNData
|
|
MFAType model.MFAType
|
|
}
|
|
|
|
func (l *Login) renderRegisterU2F(w http.ResponseWriter, r *http.Request, authReq *model.AuthRequest, err error) {
|
|
var errType, errMessage, credentialData string
|
|
var u2f *user_model.WebAuthNToken
|
|
if err == nil {
|
|
u2f, err = l.authRepo.AddMFAU2F(setContext(r.Context(), authReq.UserOrgID), authReq.UserID)
|
|
}
|
|
if err != nil {
|
|
errMessage = l.getErrorMessage(r, err)
|
|
}
|
|
if u2f != nil {
|
|
credentialData = base64.RawURLEncoding.EncodeToString(u2f.CredentialCreationData)
|
|
}
|
|
data := &u2fInitData{
|
|
webAuthNData: webAuthNData{
|
|
userData: l.getUserData(r, authReq, "Register WebAuthNToken", errType, errMessage),
|
|
CredentialCreationData: credentialData,
|
|
},
|
|
MFAType: model.MFATypeU2F,
|
|
}
|
|
l.renderer.RenderTemplate(w, r, l.renderer.Templates[tmplMFAU2FInit], data, nil)
|
|
}
|
|
|
|
func (l *Login) handleRegisterU2F(w http.ResponseWriter, r *http.Request) {
|
|
data := new(webAuthNFormData)
|
|
authReq, err := l.getAuthRequestAndParseData(r, data)
|
|
if err != nil {
|
|
l.renderError(w, r, authReq, err)
|
|
return
|
|
}
|
|
credData, err := base64.URLEncoding.DecodeString(data.CredentialData)
|
|
if err != nil {
|
|
l.renderRegisterU2F(w, r, authReq, err)
|
|
return
|
|
}
|
|
|
|
userAgentID, _ := http_mw.UserAgentIDFromCtx(r.Context())
|
|
if err = l.authRepo.VerifyMFAU2FSetup(setContext(r.Context(), authReq.UserOrgID), authReq.UserID, data.Name, userAgentID, credData); err != nil {
|
|
l.renderRegisterU2F(w, r, authReq, err)
|
|
return
|
|
}
|
|
done := &mfaDoneData{
|
|
MFAType: model.MFATypeU2F,
|
|
}
|
|
l.renderMFAInitDone(w, r, authReq, done)
|
|
}
|