passkey existing
This commit is contained in:
@@ -334,6 +334,42 @@ func (s *Server) handlePasskeyRegisterFinish(w http.ResponseWriter, r *http.Requ
|
||||
writeJSON(w, http.StatusOK, map[string]any{"user": publicUser(user)})
|
||||
}
|
||||
|
||||
func (s *Server) handleCurrentUserPasskeyRegisterBegin(w http.ResponseWriter, r *http.Request) {
|
||||
principal, _ := requirePrincipal(r)
|
||||
if !requireSessionPrincipal(w, principal) {
|
||||
return
|
||||
}
|
||||
options, challengeID, err := s.auth.BeginCurrentUserPasskeyRegistration(r.Context(), principal)
|
||||
if err != nil {
|
||||
writeJSONWithStatus(w, http.StatusBadRequest, map[string]string{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusOK, map[string]any{"challengeId": challengeID, "options": options})
|
||||
}
|
||||
|
||||
func (s *Server) handleCurrentUserPasskeyRegisterFinish(w http.ResponseWriter, r *http.Request) {
|
||||
principal, _ := requirePrincipal(r)
|
||||
if !requireSessionPrincipal(w, principal) {
|
||||
return
|
||||
}
|
||||
challengeID := r.URL.Query().Get("challengeId")
|
||||
if challengeID == "" {
|
||||
var req passkeyFinishRequest
|
||||
_ = json.NewDecoder(r.Body).Decode(&req)
|
||||
challengeID = req.ChallengeID
|
||||
}
|
||||
if challengeID == "" {
|
||||
writeJSONWithStatus(w, http.StatusBadRequest, map[string]string{"error": "challengeId is required"})
|
||||
return
|
||||
}
|
||||
user, err := s.auth.FinishCurrentUserPasskeyRegistration(r.Context(), principal, challengeID, r)
|
||||
if err != nil {
|
||||
writeJSONWithStatus(w, http.StatusBadRequest, map[string]string{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusOK, map[string]any{"user": publicUser(user)})
|
||||
}
|
||||
|
||||
func (s *Server) handlePasskeyLoginBegin(w http.ResponseWriter, r *http.Request) {
|
||||
if !s.allowAuthAttempt(w, r) {
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user