feat: implement passkey registration flow

This commit is contained in:
Prad Nukala
2024-12-09 16:23:18 -05:00
parent 27d4dfcdfd
commit 0e8b92e53d
11 changed files with 182 additions and 82 deletions
+19 -6
View File
@@ -3,7 +3,6 @@ package database
import (
"net/http"
"github.com/go-webauthn/webauthn/protocol"
"github.com/labstack/echo/v4"
"gorm.io/gorm"
)
@@ -17,13 +16,27 @@ var (
ErrUserNotFound = echo.NewHTTPError(http.StatusNotFound, "User not found")
)
// Define the credential structure matching our frontend data
type Credential struct {
ID string `json:"id"`
RawID string `json:"rawId"`
Type string `json:"type"`
AuthenticatorAttachment string `json:"authenticatorAttachment"`
Transports []string `json:"transports"`
ClientExtensionResults map[string]interface{} `json:"clientExtensionResults"`
Response struct {
AttestationObject string `json:"attestationObject"`
ClientDataJSON string `json:"clientDataJSON"`
} `json:"response"`
}
type User struct {
gorm.Model
Address string `json:"address"`
Handle string `json:"handle"`
Name string `json:"name"`
CID string `json:"cid"`
Credentials []*protocol.CredentialDescriptor `json:"credentials"`
Address string `json:"address"`
Handle string `json:"handle"`
Name string `json:"name"`
CID string `json:"cid"`
Credentials []*Credential `json:"credentials"`
}
type Session struct {
@@ -6,11 +6,11 @@ import (
"github.com/onsonr/sonr/pkg/blocks/text"
)
templ ProfileFormView(turnstileSiteKey string) {
templ ProfileFormView(data forms.CreateProfileData) {
@layout.Root("New Profile | Sonr.ID") {
@layout.Container() {
@text.Header("Create a Profile", "Enter some basic information about yourself.")
@forms.CreateProfile("/register/start", "POST")
@forms.CreateProfile("/register/start", "POST", data)
}
}
}
@@ -14,7 +14,7 @@ import (
"github.com/onsonr/sonr/pkg/blocks/text"
)
func ProfileFormView(turnstileSiteKey string) templ.Component {
func ProfileFormView(data forms.CreateProfileData) templ.Component {
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
@@ -67,7 +67,7 @@ func ProfileFormView(turnstileSiteKey string) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = forms.CreateProfile("/register/start", "POST").Render(ctx, templ_7745c5c3_Buffer)
templ_7745c5c3_Err = forms.CreateProfile("/register/start", "POST", data).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
-8
View File
@@ -1,7 +1,6 @@
package session
import (
"fmt"
"regexp"
"strings"
@@ -34,13 +33,6 @@ func (s *HTTPContext) InitSession() error {
return err
}
}
fmt.Println(sess.BrowserName)
fmt.Println(sess.BrowserVersion)
fmt.Println(sess.UserArchitecture)
fmt.Println(sess.Platform)
fmt.Println(sess.PlatformVersion)
fmt.Println(sess.DeviceModel)
s.sess = &sess
return nil
}
+3 -1
View File
@@ -4,12 +4,13 @@ import (
"net/http"
"github.com/labstack/echo/v4"
"github.com/onsonr/sonr/pkg/gateway/config"
"github.com/onsonr/sonr/pkg/gateway/internal/database"
"gorm.io/gorm"
)
// Middleware creates a new session middleware
func Middleware(db *gorm.DB) echo.MiddlewareFunc {
func Middleware(db *gorm.DB, env config.Env) echo.MiddlewareFunc {
return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
cc := NewHTTPContext(c, db)
@@ -26,6 +27,7 @@ type HTTPContext struct {
echo.Context
db *gorm.DB
sess *database.Session
env config.Env
}
// Get returns the HTTPContext from the echo context