jwt

package
v0.15.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 3, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const ScopedTokenAudience = "superplane_api"
View Source
const ScopedTokenType = "scoped"

Variables

This section is empty.

Functions

func ScopesFromPermissions added in v0.14.0

func ScopesFromPermissions(permissions []Permission) []string

Types

type Permission added in v0.14.0

type Permission struct {
	ResourceType string   `json:"resourceType"`
	Action       string   `json:"action"`
	Resources    []string `json:"resources,omitempty"`
}

func PermissionsFromScopes added in v0.14.0

func PermissionsFromScopes(scopes []string) []Permission

type ScopedTokenClaims added in v0.14.0

type ScopedTokenClaims struct {
	Subject   string             `json:"sub"`
	Audience  string             `json:"aud"`
	ExpiresAt *gojwt.NumericDate `json:"exp,omitempty"`
	NotBefore *gojwt.NumericDate `json:"nbf,omitempty"`
	IssuedAt  *gojwt.NumericDate `json:"iat,omitempty"`
	TokenType string             `json:"token_type"`
	OrgID     string             `json:"org_id"`
	Purpose   string             `json:"purpose"`
	Scopes    []string           `json:"scopes"`
}

func (ScopedTokenClaims) Valid added in v0.14.0

func (c ScopedTokenClaims) Valid() error

func (ScopedTokenClaims) VerifyAudience added in v0.14.0

func (c ScopedTokenClaims) VerifyAudience(cmp string, req bool) bool

type Signer

type Signer struct {
	Secret string
}

func NewSigner

func NewSigner(secret string) *Signer

func (*Signer) Generate

func (s *Signer) Generate(subject string, duration time.Duration) (string, error)

func (*Signer) GenerateScopedToken added in v0.14.0

func (s *Signer) GenerateScopedToken(claims ScopedTokenClaims, duration time.Duration) (string, error)

func (*Signer) GenerateWithClaims added in v0.14.0

func (s *Signer) GenerateWithClaims(duration time.Duration, extraClaims map[string]string) (string, error)

GenerateWithClaims creates a JWT with the standard time claims plus any additional custom claims. Extra claims must not override the reserved time claims (iat, nbf, exp).

func (*Signer) Validate

func (s *Signer) Validate(tokenString, subject string) error

func (*Signer) ValidateAndGetClaims

func (s *Signer) ValidateAndGetClaims(tokenString string) (jwt.MapClaims, error)

ValidateAndGetClaims validates a JWT token and returns the claims

func (*Signer) ValidateScopedToken added in v0.14.0

func (s *Signer) ValidateScopedToken(tokenString string) (*ScopedTokenClaims, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL