Files
sonr/pkg/workers/handlers/auth.go
T

70 lines
2.3 KiB
Go
Raw Normal View History

package handlers
import (
"github.com/go-webauthn/webauthn/protocol"
"github.com/labstack/echo/v4"
)
// ╭───────────────────────────────────────────────────────────╮
// │ Login Handlers │
// ╰───────────────────────────────────────────────────────────╯
2024-10-11 16:47:52 -04:00
func LoginSubjectCheck(e echo.Context) error {
return e.JSON(200, "HandleCredentialAssertion")
}
2024-10-11 16:47:52 -04:00
func LoginSubjectStart(e echo.Context) error {
opts := &protocol.PublicKeyCredentialRequestOptions{
UserVerification: "preferred",
Challenge: []byte("challenge"),
}
return e.JSON(200, opts)
}
func LoginSubjectFinish(e echo.Context) error {
2024-10-11 16:47:52 -04:00
var crr protocol.CredentialAssertionResponse
if err := e.Bind(&crr); err != nil {
return err
}
return e.JSON(200, crr)
}
// ╭───────────────────────────────────────────────────────────╮
// │ Register Handlers │
// ╰───────────────────────────────────────────────────────────╯
func RegisterSubjectCheck(e echo.Context) error {
credentialID := e.FormValue("credentialID")
return e.JSON(200, credentialID)
}
func RegisterSubjectStart(e echo.Context) error {
2024-10-11 16:47:52 -04:00
opts := &protocol.PublicKeyCredentialCreationOptions{
RelyingParty: protocol.RelyingPartyEntity{
CredentialEntity: protocol.CredentialEntity{
Name: "Sonr",
},
ID: "https://sonr.io",
},
}
2024-10-11 16:47:52 -04:00
return e.JSON(200, opts)
}
func RegisterSubjectFinish(e echo.Context) error {
// Deserialize the JSON into a temporary struct
var ccr protocol.CredentialCreationResponse
2024-10-11 16:47:52 -04:00
if err := e.Bind(&ccr); err != nil {
return err
}
//
// // Parse the CredentialCreationResponse
// parsedData, err := ccr.Parse()
// if err != nil {
// return e.JSON(500, err.Error())
// }
//
// // Create the Credential
// // credential := orm.NewCredential(parsedData, e.Request().Host, "")
2024-10-11 16:47:52 -04:00
return e.JSON(200, ccr)
}