mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-03 18:01:39 +00:00
feature/implement vault allocation (#11)
* feat: add authentication middleware * feat: add REST API endpoints for database interactions * refactor: move DiscoveryDocument Pkl schema to oidc module * fix: replace sonrd with test_node.sh * feat: use NFT keeper to mint DID namespace NFT * refactor: move NFT class configuration to types * feat: add GlobalIntegrity genesis state * fix: ensure GlobalIntegrity is initialized in genesis * refactor: update all references to transactions module * refactor: improve genesis state struct * chore(did): update discovery endpoint to reflect base url * feat: remove unused context cache and client code * refactor: remove middleware dependency from keeper * feat: Add new query handlers for DID module * feat: Implement unimplemented params queries * feat: add support for first-party caveats * refactor: move motr command to cmd directory * feat: add support for GitHub releases * fix(motr): build app.wasm for motr package * feat: add card component * feat: add IndexedDB support for persistent storage * feat: Add Row and Column components * feat: add and components * refactor: improve button component * refactor: remove unnecessary button parameter in renderButton * feat: add vault service endpoint * feat: add input component
This commit is contained in:
+47
-24
@@ -1,41 +1,61 @@
|
||||
package mdw
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
echojwt "github.com/labstack/echo-jwt/v4"
|
||||
"github.com/labstack/echo/v4"
|
||||
"gopkg.in/macaroon.v2"
|
||||
)
|
||||
|
||||
type Authz struct {
|
||||
echo.Context
|
||||
echojwt.Config
|
||||
const (
|
||||
OriginMacroonCaveat MacroonCaveat = "origin"
|
||||
ScopesMacroonCaveat MacroonCaveat = "scopes"
|
||||
SubjectMacroonCaveat MacroonCaveat = "subject"
|
||||
ExpMacroonCaveat MacroonCaveat = "exp"
|
||||
TokenMacroonCaveat MacroonCaveat = "token"
|
||||
)
|
||||
|
||||
signKey []byte
|
||||
type MacroonCaveat string
|
||||
|
||||
func (c MacroonCaveat) Equal(other string) bool {
|
||||
return string(c) == other
|
||||
}
|
||||
|
||||
func newAuthz(c echo.Context, signKey []byte) *Authz {
|
||||
return &Authz{Context: c, signKey: signKey}
|
||||
func (c MacroonCaveat) String() string {
|
||||
return string(c)
|
||||
}
|
||||
|
||||
func (a *Authz) Accessible(route string, handler echo.HandlerFunc) echo.HandlerFunc {
|
||||
// Verify the macaroon
|
||||
// verified := a.Verify(a.signKey, func(caveat string) error {
|
||||
// Implement your caveat verification logic here
|
||||
// For example, you might check if the caveat is still valid (e.g., not expired)
|
||||
// return nil // Return nil if the caveat is valid
|
||||
// }, nil)
|
||||
// if !verified {
|
||||
// return func(c echo.Context) error {
|
||||
// return c.JSON(http.StatusUnauthorized, map[string]string{"error": "Invalid macaroon"})
|
||||
// }
|
||||
// }
|
||||
a.SetPath(route)
|
||||
return handler
|
||||
func (c MacroonCaveat) Verify(value string) error {
|
||||
switch c {
|
||||
case OriginMacroonCaveat:
|
||||
return nil
|
||||
case ScopesMacroonCaveat:
|
||||
return nil
|
||||
case SubjectMacroonCaveat:
|
||||
return nil
|
||||
case ExpMacroonCaveat:
|
||||
// Check if the expiration time is still valid
|
||||
exp, err := time.Parse(time.RFC3339, value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if time.Now().After(exp) {
|
||||
return fmt.Errorf("expired")
|
||||
}
|
||||
return nil
|
||||
case TokenMacroonCaveat:
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("unknown caveat: %s", c)
|
||||
}
|
||||
}
|
||||
|
||||
func ValidateMacaroonMiddleware(secretKey []byte, location string) echo.MiddlewareFunc {
|
||||
var MacroonCaveats = []MacroonCaveat{OriginMacroonCaveat, ScopesMacroonCaveat, SubjectMacroonCaveat, ExpMacroonCaveat, TokenMacroonCaveat}
|
||||
|
||||
func MacaroonMiddleware(secretKeyStr string, location string) echo.MiddlewareFunc {
|
||||
secretKey := []byte(secretKeyStr)
|
||||
return func(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
// Extract the macaroon from the Authorization header
|
||||
@@ -57,8 +77,11 @@ func ValidateMacaroonMiddleware(secretKey []byte, location string) echo.Middlewa
|
||||
|
||||
// Verify the macaroon
|
||||
err = token.Verify(secretKey, func(caveat string) error {
|
||||
// Implement your caveat verification logic here
|
||||
// For example, you might check if the caveat is still valid (e.g., not expired)
|
||||
for _, c := range MacroonCaveats {
|
||||
if c.String() == caveat {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return nil // Return nil if the caveat is valid
|
||||
}, nil)
|
||||
if err != nil {
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
package mdw
|
||||
|
||||
type AuthClient struct{}
|
||||
@@ -1,7 +1,5 @@
|
||||
package mdw
|
||||
|
||||
import "github.com/labstack/echo/v4"
|
||||
|
||||
type RequestHeaders struct {
|
||||
Authorization *string `header:"Authorization"`
|
||||
CacheControl *string `header:"Cache-Control"`
|
||||
@@ -55,8 +53,3 @@ type ResponseHeaders struct {
|
||||
HXTriggerAfterSettle *string `header:"HX-Trigger-After-Settle"`
|
||||
HXTriggerAfterSwap *string `header:"HX-Trigger-After-Swap"`
|
||||
}
|
||||
|
||||
func bindRequestHeaders(c echo.Context) {
|
||||
headers := new(RequestHeaders)
|
||||
c.Bind(headers)
|
||||
}
|
||||
|
||||
+21
-20
@@ -10,13 +10,10 @@ import (
|
||||
"github.com/segmentio/ksuid"
|
||||
)
|
||||
|
||||
// UseSession establishes a Session Cookie.
|
||||
func UseSession(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
sc := newSession(c)
|
||||
bindRequestHeaders(sc)
|
||||
return next(sc)
|
||||
}
|
||||
type Session struct {
|
||||
echo.Context
|
||||
htmx *htmx.HTMX
|
||||
dB *db.DB
|
||||
}
|
||||
|
||||
// GetSession returns the current Session
|
||||
@@ -24,25 +21,29 @@ func GetSession(c echo.Context) *Session {
|
||||
return c.(*Session)
|
||||
}
|
||||
|
||||
type Session struct {
|
||||
echo.Context
|
||||
htmx *htmx.HTMX
|
||||
dB *db.DB
|
||||
}
|
||||
|
||||
func (c *Session) ID() string {
|
||||
return readCookie(c, "session")
|
||||
}
|
||||
|
||||
func (c *Session) Htmx() *htmx.HTMX {
|
||||
return c.htmx
|
||||
// UseSession establishes a Session Cookie.
|
||||
func UseSession(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
sc := initSession(c)
|
||||
headers := new(RequestHeaders)
|
||||
sc.Bind(headers)
|
||||
return next(sc)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Session) DB() *db.DB {
|
||||
return c.dB
|
||||
}
|
||||
|
||||
func newSession(c echo.Context) *Session {
|
||||
func (c *Session) Htmx() *htmx.HTMX {
|
||||
return c.htmx
|
||||
}
|
||||
|
||||
func (c *Session) ID() string {
|
||||
return readCookie(c, "session")
|
||||
}
|
||||
|
||||
func initSession(c echo.Context) *Session {
|
||||
s := &Session{Context: c}
|
||||
if val := readCookie(c, "session"); val == "" {
|
||||
id := ksuid.New().String()
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
package mdw
|
||||
Reference in New Issue
Block a user