mirror of
https://github.com/zitadel/zitadel.git
synced 2025-04-24 00:51:31 +00:00

* begin init checks for projections * first projection checks * debug notification providers with query fixes * more projections and first index * more projections * more projections * finish projections * fix tests (remove db name) * create tables in setup * fix logging / error handling * add tenant to views * rename tenant to instance_id * add instance_id to all projections * add instance_id to all queries * correct instance_id on projections * add instance_id to failed_events * use separate context for instance * implement features projection * implement features projection * remove unique constraint from setup when migration failed * add error to failed setup event * add instance_id to primary keys * fix IAM projection * remove old migrations folder * fix keysFromYAML test
72 lines
2.2 KiB
Go
72 lines
2.2 KiB
Go
package login
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"net/http"
|
|
|
|
"github.com/caos/zitadel/internal/domain"
|
|
)
|
|
|
|
const (
|
|
tmplPasswordlessVerification = "passwordlessverification"
|
|
)
|
|
|
|
type passwordlessData struct {
|
|
webAuthNData
|
|
PasswordLogin bool
|
|
}
|
|
|
|
type passwordlessFormData struct {
|
|
webAuthNFormData
|
|
PasswordLogin bool `schema:"passwordlogin"`
|
|
}
|
|
|
|
func (l *Login) renderPasswordlessVerification(w http.ResponseWriter, r *http.Request, authReq *domain.AuthRequest, passwordSet bool, err error) {
|
|
var errID, errMessage, credentialData string
|
|
var webAuthNLogin *domain.WebAuthNLogin
|
|
if err == nil {
|
|
webAuthNLogin, err = l.authRepo.BeginPasswordlessLogin(setContext(r.Context(), authReq.UserOrgID), authReq.UserID, authReq.UserOrgID, authReq.ID, authReq.AgentID, authReq.InstanceID)
|
|
}
|
|
if err != nil {
|
|
errID, errMessage = l.getErrorMessage(r, err)
|
|
}
|
|
if webAuthNLogin != nil {
|
|
credentialData = base64.RawURLEncoding.EncodeToString(webAuthNLogin.CredentialAssertionData)
|
|
}
|
|
if passwordSet && authReq.LoginPolicy != nil {
|
|
passwordSet = authReq.LoginPolicy.AllowUsernamePassword
|
|
}
|
|
data := &passwordlessData{
|
|
webAuthNData{
|
|
userData: l.getUserData(r, authReq, "Login Passwordless", errID, errMessage),
|
|
CredentialCreationData: credentialData,
|
|
},
|
|
passwordSet,
|
|
}
|
|
l.renderer.RenderTemplate(w, r, l.getTranslator(authReq), l.renderer.Templates[tmplPasswordlessVerification], data, nil)
|
|
}
|
|
|
|
func (l *Login) handlePasswordlessVerification(w http.ResponseWriter, r *http.Request) {
|
|
formData := new(passwordlessFormData)
|
|
authReq, err := l.getAuthRequestAndParseData(r, formData)
|
|
if err != nil {
|
|
l.renderError(w, r, authReq, err)
|
|
return
|
|
}
|
|
if formData.PasswordLogin {
|
|
l.renderPassword(w, r, authReq, nil)
|
|
return
|
|
}
|
|
credData, err := base64.URLEncoding.DecodeString(formData.CredentialData)
|
|
if err != nil {
|
|
l.renderPasswordlessVerification(w, r, authReq, formData.PasswordLogin, err)
|
|
return
|
|
}
|
|
err = l.authRepo.VerifyPasswordless(setContext(r.Context(), authReq.UserOrgID), authReq.UserID, authReq.UserOrgID, authReq.ID, authReq.AgentID, authReq.InstanceID, credData, domain.BrowserInfoFromRequest(r))
|
|
if err != nil {
|
|
l.renderPasswordlessVerification(w, r, authReq, formData.PasswordLogin, err)
|
|
return
|
|
}
|
|
l.renderNextStep(w, r, authReq)
|
|
}
|