mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 19:17:32 +00:00
feat: run on a single port (#3163)
* start v2 * start * run * some cleanup * remove v2 pkg again * simplify * webauthn * remove unused config * fix login path in Dockerfile * fix asset_generator.go * health handler * fix grpc web * refactor * merge * build new main.go * run new main.go * update logging pkg * fix error msg * update logging * cleanup * cleanup * go mod tidy * change localDevMode * fix customEndpoints * update logging * comments * change local flag to external configs * fix location generated go code * fix Co-authored-by: fforootd <florian@caos.ch>
This commit is contained in:
@@ -3,40 +3,35 @@ package webauthn
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
|
||||
"github.com/duo-labs/webauthn/protocol"
|
||||
"github.com/duo-labs/webauthn/webauthn"
|
||||
|
||||
"github.com/caos/zitadel/internal/config/systemdefaults"
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
)
|
||||
|
||||
type WebAuthN struct {
|
||||
webLogin *webauthn.WebAuthn
|
||||
webConsole *webauthn.WebAuthn
|
||||
webAuthN *webauthn.WebAuthn
|
||||
}
|
||||
|
||||
func StartServer(sd systemdefaults.WebAuthN) (*WebAuthN, error) {
|
||||
webLogin, err := webauthn.New(&webauthn.Config{
|
||||
RPDisplayName: sd.DisplayName,
|
||||
RPID: sd.ID,
|
||||
RPOrigin: sd.OriginLogin,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
webConsole, err := webauthn.New(&webauthn.Config{
|
||||
RPDisplayName: sd.DisplayName,
|
||||
RPID: sd.ID,
|
||||
RPOrigin: sd.OriginConsole,
|
||||
type Config struct {
|
||||
ID string
|
||||
Origin string
|
||||
DisplayName string
|
||||
}
|
||||
|
||||
func StartServer(config Config) (*WebAuthN, error) {
|
||||
webAuthN, err := webauthn.New(&webauthn.Config{
|
||||
RPDisplayName: config.DisplayName,
|
||||
RPID: config.ID,
|
||||
RPOrigin: config.Origin,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &WebAuthN{
|
||||
webLogin: webLogin,
|
||||
webConsole: webConsole,
|
||||
webAuthN: webAuthN,
|
||||
}, err
|
||||
}
|
||||
|
||||
@@ -78,7 +73,7 @@ func (w *WebAuthN) BeginRegistration(user *domain.Human, accountName string, aut
|
||||
CredentialID: cred.ID,
|
||||
}
|
||||
}
|
||||
credentialOptions, sessionData, err := w.web(isLoginUI).BeginRegistration(
|
||||
credentialOptions, sessionData, err := w.webAuthN.BeginRegistration(
|
||||
&webUser{
|
||||
Human: user,
|
||||
accountName: accountName,
|
||||
@@ -115,7 +110,7 @@ func (w *WebAuthN) FinishRegistration(user *domain.Human, webAuthN *domain.WebAu
|
||||
return nil, caos_errs.ThrowInternal(err, "WEBAU-sEr8c", "Errors.User.WebAuthN.ErrorOnParseCredential")
|
||||
}
|
||||
sessionData := WebAuthNToSessionData(webAuthN)
|
||||
credential, err := w.web(isLoginUI).CreateCredential(
|
||||
credential, err := w.webAuthN.CreateCredential(
|
||||
&webUser{
|
||||
Human: user,
|
||||
},
|
||||
@@ -135,7 +130,7 @@ func (w *WebAuthN) FinishRegistration(user *domain.Human, webAuthN *domain.WebAu
|
||||
}
|
||||
|
||||
func (w *WebAuthN) BeginLogin(user *domain.Human, userVerification domain.UserVerificationRequirement, isLoginUI bool, webAuthNs ...*domain.WebAuthNToken) (*domain.WebAuthNLogin, error) {
|
||||
assertion, sessionData, err := w.web(isLoginUI).BeginLogin(&webUser{
|
||||
assertion, sessionData, err := w.webAuthN.BeginLogin(&webUser{
|
||||
Human: user,
|
||||
credentials: WebAuthNsToCredentials(webAuthNs),
|
||||
}, webauthn.WithUserVerification(UserVerificationFromDomain(userVerification)))
|
||||
@@ -163,7 +158,7 @@ func (w *WebAuthN) FinishLogin(user *domain.Human, webAuthN *domain.WebAuthNLogi
|
||||
Human: user,
|
||||
credentials: WebAuthNsToCredentials(webAuthNs),
|
||||
}
|
||||
credential, err := w.web(isLoginUI).ValidateLogin(webUser, WebAuthNLoginToSessionData(webAuthN), assertionData)
|
||||
credential, err := w.webAuthN.ValidateLogin(webUser, WebAuthNLoginToSessionData(webAuthN), assertionData)
|
||||
if err != nil {
|
||||
return nil, 0, caos_errs.ThrowInternal(err, "WEBAU-3M9si", "Errors.User.WebAuthN.ValidateLoginFailed")
|
||||
}
|
||||
@@ -173,10 +168,3 @@ func (w *WebAuthN) FinishLogin(user *domain.Human, webAuthN *domain.WebAuthNLogi
|
||||
}
|
||||
return credential.ID, credential.Authenticator.SignCount, nil
|
||||
}
|
||||
|
||||
func (w *WebAuthN) web(isLoginUI bool) *webauthn.WebAuthn {
|
||||
if isLoginUI {
|
||||
return w.webLogin
|
||||
}
|
||||
return w.webConsole
|
||||
}
|
||||
|
Reference in New Issue
Block a user