mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-04 02:11:40 +00:00
(no commit message provided)
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
pages "github.com/onsonr/hway/pkg/vault/components"
|
||||
"github.com/onsonr/hway/pkg/vault/middleware"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
var Login = loginHandler{}
|
||||
|
||||
type loginHandler struct{}
|
||||
|
||||
func (h loginHandler) Page(e echo.Context) error {
|
||||
return middleware.Render(e, pages.Login(middleware.SessionID(e)))
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
var OIDC = oidcHandler{}
|
||||
|
||||
type oidcHandler struct{}
|
||||
|
||||
func (p oidcHandler) HandleAuthorize(e echo.Context) error {
|
||||
// Implement authorization endpoint using passkey authentication
|
||||
// Store session data in cache
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p oidcHandler) HandleToken(e echo.Context) error {
|
||||
// Implement token endpoint
|
||||
// Use cached session data for validation
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p oidcHandler) HandleUserInfo(e echo.Context) error {
|
||||
// Implement userinfo endpoint
|
||||
// Use cached session data for validation
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p oidcHandler) HandleDiscovery(e echo.Context) error {
|
||||
baseURL := "https://" + e.Request().Host // Ensure this is the correct base URL for your service
|
||||
|
||||
discoveryDoc := DiscoveryDocument{
|
||||
Issuer: baseURL,
|
||||
AuthorizationEndpoint: baseURL + "/authorize",
|
||||
TokenEndpoint: baseURL + "/token",
|
||||
UserinfoEndpoint: baseURL + "/userinfo",
|
||||
JwksURI: baseURL + "/jwks", // You'll need to implement this endpoint
|
||||
RegistrationEndpoint: baseURL + "/register",
|
||||
ScopesSupported: []string{"openid", "profile", "email"},
|
||||
ResponseTypesSupported: []string{"code"},
|
||||
SubjectTypesSupported: []string{"public"},
|
||||
IDTokenSigningAlgValuesSupported: []string{"RS256"},
|
||||
ClaimsSupported: []string{"sub", "iss", "name", "email"},
|
||||
GrantTypesSupported: []string{"authorization_code", "refresh_token"},
|
||||
TokenEndpointAuthMethodsSupported: []string{"client_secret_basic", "client_secret_post"},
|
||||
}
|
||||
return e.JSON(200, discoveryDoc)
|
||||
}
|
||||
|
||||
type DiscoveryDocument struct {
|
||||
Issuer string `json:"issuer"`
|
||||
AuthorizationEndpoint string `json:"authorization_endpoint"`
|
||||
TokenEndpoint string `json:"token_endpoint"`
|
||||
UserinfoEndpoint string `json:"userinfo_endpoint"`
|
||||
JwksURI string `json:"jwks_uri"`
|
||||
RegistrationEndpoint string `json:"registration_endpoint"`
|
||||
ScopesSupported []string `json:"scopes_supported"`
|
||||
ResponseTypesSupported []string `json:"response_types_supported"`
|
||||
SubjectTypesSupported []string `json:"subject_types_supported"`
|
||||
IDTokenSigningAlgValuesSupported []string `json:"id_token_signing_alg_values_supported"`
|
||||
ClaimsSupported []string `json:"claims_supported"`
|
||||
GrantTypesSupported []string `json:"grant_types_supported"`
|
||||
TokenEndpointAuthMethodsSupported []string `json:"token_endpoint_auth_methods_supported"`
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"github.com/onsonr/hway/pkg/vault/components"
|
||||
"github.com/onsonr/hway/pkg/vault/middleware"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
var Session = sessionHandler{}
|
||||
|
||||
type sessionHandler struct{}
|
||||
|
||||
func (h sessionHandler) Page(e echo.Context) error {
|
||||
return middleware.Render(e, components.Home(middleware.SessionID(e)))
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/onsonr/hway/internal/orm"
|
||||
pages "github.com/onsonr/hway/pkg/vault/components"
|
||||
"github.com/onsonr/hway/pkg/vault/middleware"
|
||||
"github.com/go-webauthn/webauthn/protocol"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
var Register = registerHandler{}
|
||||
|
||||
type registerHandler struct{}
|
||||
|
||||
func (h registerHandler) Start(e echo.Context) error {
|
||||
return e.JSON(0, nil)
|
||||
}
|
||||
|
||||
func (h registerHandler) Finish(e echo.Context) error {
|
||||
// Get the serialized credential data from the form
|
||||
credentialDataJSON := e.FormValue("credentialData")
|
||||
|
||||
// Deserialize the JSON into a temporary struct
|
||||
var ccr protocol.CredentialCreationResponse
|
||||
err := json.Unmarshal([]byte(credentialDataJSON), &ccr)
|
||||
if err != nil {
|
||||
return e.JSON(500, err.Error())
|
||||
}
|
||||
|
||||
// Parse the CredentialCreationResponse
|
||||
parsedData, err := ccr.Parse()
|
||||
if err != nil {
|
||||
return e.JSON(500, err.Error())
|
||||
}
|
||||
|
||||
// Create the Credential
|
||||
credential := orm.MakeNewCredential(parsedData)
|
||||
|
||||
// Set additional fields
|
||||
credential.DisplayName = ccr.ID // You might want to set this to a more meaningful value
|
||||
credential.Origin = e.Request().Host // Set the origin to the current host
|
||||
credential.Controller = "" // Set this to the appropriate controller value
|
||||
return e.JSON(200, fmt.Sprintf("REGISTER: %s", string(credential.ID)))
|
||||
}
|
||||
|
||||
// FormPage returns the page for registering a new user
|
||||
func (h registerHandler) FormPage(e echo.Context) error {
|
||||
return middleware.Render(e, pages.Register(middleware.SessionID(e), string(middleware.Cache.GetChallenge(e))))
|
||||
}
|
||||
Reference in New Issue
Block a user