feat: implement passkey registration flow

This commit is contained in:
Prad Nukala
2024-12-10 14:37:54 -05:00
parent b51c36645e
commit 04d929aae9
7 changed files with 32 additions and 35 deletions
+17 -3
View File
@@ -6,9 +6,23 @@ import (
"net/http"
"github.com/labstack/echo/v4"
"github.com/onsonr/sonr/internal/database/sessions"
)
// Define the credential structure matching our frontend data
type Credential struct {
Handle string `json:"handle"`
ID string `json:"id"`
RawID string `json:"rawId"`
Type string `json:"type"`
AuthenticatorAttachment string `json:"authenticatorAttachment"`
Transports string `json:"transports"`
ClientExtensionResults map[string]string `json:"clientExtensionResults"`
Response struct {
AttestationObject string `json:"attestationObject"`
ClientDataJSON string `json:"clientDataJSON"`
} `json:"response"`
}
type CreateProfileData struct {
TurnstileSiteKey string
FirstNumber int
@@ -35,8 +49,8 @@ func (d CreateProfileData) IsHumanLabel() string {
return fmt.Sprintf("What is %d + %d?", d.FirstNumber, d.LastNumber)
}
func extractCredentialDescriptor(jsonString string) (*sessions.Credential, error) {
cred := &sessions.Credential{}
func extractCredentialDescriptor(jsonString string) (*Credential, error) {
cred := &Credential{}
// Unmarshal the credential JSON
if err := json.Unmarshal([]byte(jsonString), cred); err != nil {
return nil, echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("invalid credential format: %v", err))