feat: add User-Agent and Platform to session

This commit is contained in:
Prad Nukala
2024-10-12 12:52:20 -04:00
parent 58aa71997d
commit 104df074e9
6 changed files with 80 additions and 137 deletions
+4 -4
View File
@@ -10,9 +10,9 @@ import (
func Route(c echo.Context) error {
s := ctx.GetSession(c)
log.Printf("Session ID: %s", s.ID())
log.Printf("Session Origin: %s", s.Origin())
log.Printf("Session Address: %s", s.Address())
log.Printf("Session ChainID: %s", s.ChainID())
log.Printf("Session ID: %s", s.ID)
log.Printf("Session Origin: %s", s.Origin)
log.Printf("Session Address: %s", s.Address)
log.Printf("Session ChainID: %s", s.ChainID)
return ctx.RenderTempl(c, View())
}
+19 -11
View File
@@ -3,6 +3,9 @@ package handlers
import (
"github.com/go-webauthn/webauthn/protocol"
"github.com/labstack/echo/v4"
"github.com/onsonr/sonr/internal/ctx"
"github.com/onsonr/sonr/internal/orm"
)
// ╭───────────────────────────────────────────────────────────╮
@@ -34,20 +37,25 @@ func LoginSubjectFinish(e echo.Context) error {
// ╰───────────────────────────────────────────────────────────╯
func RegisterSubjectCheck(e echo.Context) error {
credentialID := e.FormValue("credentialID")
return e.JSON(200, credentialID)
subject := e.FormValue("subject")
return e.JSON(200, subject)
}
func RegisterSubjectStart(e echo.Context) error {
opts := &protocol.PublicKeyCredentialCreationOptions{
RelyingParty: protocol.RelyingPartyEntity{
CredentialEntity: protocol.CredentialEntity{
Name: "Sonr",
},
ID: "https://sonr.io",
},
// Get subject and address
subject := e.FormValue("subject")
address := e.FormValue("address")
// Set address in session
s := ctx.GetSession(e)
s = ctx.SetAddress(e, address)
// Get challenge
chal, err := s.GetChallenge(subject)
if err != nil {
return err
}
return e.JSON(200, opts)
return e.JSON(201, orm.NewCredentialCreationOptions(subject, address, chal))
}
func RegisterSubjectFinish(e echo.Context) error {
@@ -65,5 +73,5 @@ func RegisterSubjectFinish(e echo.Context) error {
//
// // Create the Credential
// // credential := orm.NewCredential(parsedData, e.Request().Host, "")
return e.JSON(200, ccr)
return e.JSON(201, ccr)
}