mirror of
https://github.com/onsonr/sonr.git
synced 2025-03-10 13:07:09 +00:00
feat: add DID-based authentication middleware
This commit is contained in:
parent
f8d362352d
commit
6fbcb7cef5
@ -10,8 +10,8 @@ import (
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/labstack/echo/v4/middleware"
|
||||
"github.com/onsonr/sonr/crypto/ucan"
|
||||
"github.com/onsonr/sonr/pkg/common/didauth/producer"
|
||||
"github.com/onsonr/sonr/pkg/common/ipfs"
|
||||
"github.com/onsonr/sonr/pkg/common/producer"
|
||||
"github.com/onsonr/sonr/pkg/gateway"
|
||||
"github.com/onsonr/sonr/pkg/gateway/config"
|
||||
)
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"syscall/js"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/onsonr/sonr/pkg/common/dids"
|
||||
"github.com/onsonr/sonr/pkg/common/didauth/controller"
|
||||
"github.com/onsonr/sonr/pkg/vault"
|
||||
"github.com/onsonr/sonr/pkg/vault/types"
|
||||
)
|
||||
@ -48,7 +48,7 @@ func main() {
|
||||
|
||||
e := echo.New()
|
||||
e.Use(vault.WasmContextMiddleware)
|
||||
e.Use(dids.Middleware(nil))
|
||||
e.Use(controller.Middleware(nil))
|
||||
vault.RegisterRoutes(e, config)
|
||||
vault.ServeFetch(e)
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package dids
|
||||
package controller
|
||||
|
||||
import (
|
||||
"github.com/labstack/echo/v4"
|
@ -1,7 +1,7 @@
|
||||
//go:build js && wasm
|
||||
// +build js,wasm
|
||||
|
||||
package dids
|
||||
package controller
|
||||
|
||||
import (
|
||||
"fmt"
|
2
pkg/common/didauth/exports.go
Normal file
2
pkg/common/didauth/exports.go
Normal file
@ -0,0 +1,2 @@
|
||||
// Package didauth provides middleware and utilities for DID-based authentication
|
||||
package didauth
|
@ -1,6 +1,7 @@
|
||||
package producer
|
||||
|
||||
import (
|
||||
"github.com/onsonr/sonr/crypto/mpc"
|
||||
"github.com/onsonr/sonr/crypto/ucan"
|
||||
"github.com/onsonr/sonr/crypto/ucan/store"
|
||||
"github.com/onsonr/sonr/pkg/common/ipfs"
|
||||
@ -27,3 +28,11 @@ func Middleware(ipfs ipfs.Client, perms ucan.Permissions) echo.MiddlewareFunc {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func NewKeyset(c echo.Context) (mpc.Keyset, error) {
|
||||
ks, err := mpc.NewKeyset()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ks, nil
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
package producer
|
||||
|
||||
import (
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/onsonr/sonr/crypto/mpc"
|
||||
)
|
||||
|
||||
func NewKeyset(c echo.Context) (mpc.Keyset, error) {
|
||||
ks, err := mpc.NewKeyset()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ks, nil
|
||||
}
|
||||
|
||||
//
|
||||
// func GetKeyset(c echo.Context) (mpc.Keyset, error) {
|
||||
// cc, ok := c.(*SignerContext)
|
||||
// if !ok {
|
||||
// return nil, errors.New("not an SignerContext")
|
||||
// }
|
||||
// if !cc.hasKeyset {
|
||||
// return nil, fmt.Errorf("keyset not found")
|
||||
// }
|
||||
// if cc.keyset == nil {
|
||||
// return nil, fmt.Errorf("keyset is nil")
|
||||
// }
|
||||
// return cc.keyset, nil
|
||||
// }
|
||||
//
|
||||
// func NewSource(c echo.Context) (mpc.KeyshareSource, error) {
|
||||
// cc, ok := c.(*SignerContext)
|
||||
// if !ok {
|
||||
// return nil, errors.New("not an SignerContext")
|
||||
// }
|
||||
// if !cc.hasKeyset {
|
||||
// return nil, fmt.Errorf("keyset not found")
|
||||
// }
|
||||
// if cc.keyset == nil {
|
||||
// return nil, fmt.Errorf("keyset is nil")
|
||||
// }
|
||||
// src, err := mpc.NewSource(cc.keyset)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// cc.signer = src
|
||||
// cc.hasSigner = true
|
||||
// return src, nil
|
||||
// }
|
||||
//
|
||||
// func GetSource(c echo.Context) (mpc.KeyshareSource, error) {
|
||||
// cc, ok := c.(*SignerContext)
|
||||
// if !ok {
|
||||
// return nil, errors.New("not an SignerContext")
|
||||
// }
|
||||
// if !cc.hasSigner {
|
||||
// return nil, fmt.Errorf("signer not found")
|
||||
// }
|
||||
// if cc.signer == nil {
|
||||
// return nil, fmt.Errorf("signer is nil")
|
||||
// }
|
||||
// return cc.signer, nil
|
||||
// }
|
Loading…
x
Reference in New Issue
Block a user