mirror of
https://github.com/hanzoai/commerce.git
synced 2026-10-30 15:08:42 +00:00
Multi-tenant commerce and billing: orders, subscriptions, invoices, plans, usage metering and a credit ledger. One Go binary. MIT OR Apache-2.0. Claude-Session: https://claude.ai/code/session_01SAtaDFm8VDiWrhYHNNtxMw
62 lines
1.3 KiB
Go
62 lines
1.3 KiB
Go
package oauthtoken
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"github.com/hanzoai/commerce/util/bit"
|
|
"github.com/hanzoai/commerce/util/jwt"
|
|
)
|
|
|
|
type Type string
|
|
|
|
const (
|
|
// Internal Claims used to store Access Token claims
|
|
Reference Type = "reference"
|
|
|
|
// Special Username/Password OAuth grant key
|
|
Api = "api"
|
|
|
|
// Claims generated by Reference Claims
|
|
Access = "access"
|
|
|
|
// Customer is a Special Access Token generated from API Claim
|
|
Customer = "customer"
|
|
|
|
// Token issued using the Reference Claims, used only to request new Acess Claims
|
|
Refresh = "refresh"
|
|
)
|
|
|
|
// Used for Refresh and Site Tokens
|
|
type Claims struct {
|
|
jwt.Claims
|
|
AccessClaims
|
|
|
|
AppId string `json:"app,omitempty"`
|
|
UserId string `json:"usr,omitempty"`
|
|
OrganizationName string `json:"org,omitempty"`
|
|
Type Type `json:"typ,omitempty"`
|
|
Scopes []string `json:"scopes,omitempty"`
|
|
Test bool `json:"tst,omitempty"`
|
|
|
|
Permissions bit.Field `json:"bit,omitempty"`
|
|
}
|
|
|
|
func (c Claims) HasPermission(mask bit.Mask) bool {
|
|
return c.Permissions.Has(mask)
|
|
}
|
|
|
|
func (c Claims) Clone() jwt.Claimable {
|
|
return c
|
|
}
|
|
|
|
func (c Claims) JSON() string {
|
|
j, _ := json.Marshal(c)
|
|
return string(j)
|
|
}
|
|
|
|
type AccessClaims struct {
|
|
// Admin Dashboard Claims (for display)
|
|
FirstName string `json:"firstName,omitempty"`
|
|
LastName string `json:"lastName,omitempty"`
|
|
}
|