mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-03 01:41:44 +00:00
* feat: add support for DID number as primary key for Controllers * refactor: rename pkg/proxy to app/proxy * feat: add vault module keeper tests * feat(vault): add DID keeper to vault module * refactor: move vault client code to its own package * refactor(vault): extract schema definition * refactor: use vaulttypes for MsgAllocateVault * refactor: update vault assembly logic to use new methods * feat: add dwn-proxy command * refactor: remove unused context.go file * refactor: remove unused web-related code * feat: add DWN proxy server * feat: add BuildTx RPC to vault module * fix: Implement BuildTx endpoint * feat: add devbox integration to project
52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
package middleware
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
const (
|
|
OriginMacroonCaveat MacroonCaveat = "origin"
|
|
ScopesMacroonCaveat MacroonCaveat = "scopes"
|
|
SubjectMacroonCaveat MacroonCaveat = "subject"
|
|
ExpMacroonCaveat MacroonCaveat = "exp"
|
|
TokenMacroonCaveat MacroonCaveat = "token"
|
|
)
|
|
|
|
type MacroonCaveat string
|
|
|
|
func (c MacroonCaveat) Equal(other string) bool {
|
|
return string(c) == other
|
|
}
|
|
|
|
func (c MacroonCaveat) String() string {
|
|
return string(c)
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|
|
|
|
var MacroonCaveats = []MacroonCaveat{OriginMacroonCaveat, ScopesMacroonCaveat, SubjectMacroonCaveat, ExpMacroonCaveat, TokenMacroonCaveat}
|