Documentation
¶
Overview ¶
Package xpaseto contains light wrappers around aidanwoods.dev/go-paseto types with a more ergonomic API.
Index ¶
- Variables
- func AllowAudiences(auds []string) paseto.Rule
- func AllowIssuers(issuers []string) paseto.Rule
- func AllowSubjects(subs []string) paseto.Rule
- func ClaimTimeConsistency() paseto.Rule
- func NotBeforeNbf(t time.Time, tolerance time.Duration) paseto.Rule
- func NotExpired(t time.Time, tolerance time.Duration) paseto.Rule
- func NotIssuedAfter(t time.Time, tolerance time.Duration) paseto.Rule
- func TokenProtocol(token string) (paseto.Protocol, error)
- type Claim
- func ClaimAudience(aud string) Claim
- func ClaimExpiration(t time.Time) Claim
- func ClaimID(id string) Claim
- func ClaimIssuedAt(t time.Time) Claim
- func ClaimIssuer(iss string) Claim
- func ClaimNotBefore(t time.Time) Claim
- func ClaimSubject(sub string) Claim
- func NewClaim(code, name string, value any) Claim
- func RegisteredClaims() []Claim
- type Key
- type KeyEncoding
- type KeyType
- type Token
- type TokenFormat
Constants ¶
This section is empty.
Variables ¶
var ErrKeyTokenProtocolMismatch = errors.New("token's version and purpose doesn't match the key's")
ErrKeyTokenProtocolMismatch indicates that the token's version and purpose don't match the key's.
Functions ¶
func AllowAudiences ¶ added in v0.2.0
AllowAudiences checks that the token has a valid "aud" field, and that its value is contained in auds.
func AllowIssuers ¶ added in v0.2.0
AllowIssuers checks that the token has a valid "iss" field, and that its value is contained in issuers.
func AllowSubjects ¶ added in v0.2.0
AllowSubjects checks that the token has a valid "sub" field, and that its value is contained in subs.
func ClaimTimeConsistency ¶
ClaimTimeConsistency checks that the "iat", "nbf", and "exp" fields exist and are valid, and that their times are consistent with each other. Specifically it checks that iat <= nbf <= exp.
func NotBeforeNbf ¶
NotBeforeNbf checks that the token has a valid "nbf" field, and that its time is before the given time. This is the same rule as paseto.NotBeforeNbf, just with a time argument.
func NotExpired ¶
NotExpired checks that the token has a valid "exp" field, and that its time is after the given time. This is the same rule as paseto.NotExpired, just with a time argument.
func NotIssuedAfter ¶
NotIssuedAfter checks that the token has a valid "iat" field, and that its time is before the given time. This is a subset of the paseto.ValidAt rule.
Types ¶
type Claim ¶
Claim represents a token claim with a code, human-readable name, and value.
func ClaimAudience ¶
ClaimAudience creates an audience claim with the specified value.
func ClaimExpiration ¶
ClaimExpiration creates an expiration claim with the specified time.
func ClaimIssuedAt ¶
ClaimIssuedAt creates an issued at claim with the specified time.
func ClaimIssuer ¶
ClaimIssuer creates an issuer claim with the specified value.
func ClaimNotBefore ¶
ClaimNotBefore creates a not before claim with the specified time.
func ClaimSubject ¶
ClaimSubject creates a subject claim with the specified value.
func RegisteredClaims ¶ added in v0.2.0
func RegisteredClaims() []Claim
RegisteredClaims returns the registered claims with empty values.
type Key ¶
type Key struct {
// contains filtered or unexported fields
}
Key represents a PASETO key for encryption, decryption, signing, or verification.
func NewKey ¶
NewKey creates a new Key with the specified version, purpose, and underlying key. If k is nil, a new key or key pair will be generated.
func (Key) Public ¶
Public returns the public key corresponding to this private key, or nil if this is not a private key.
func (Key) Render ¶
func (k Key) Render(enc KeyEncoding) string
Render returns the key encoded in the specified format.
type KeyEncoding ¶
type KeyEncoding string
KeyEncoding represents the encoding format for keys.
const ( KeyEncodingHex KeyEncoding = "hex" KeyEncodingPEM KeyEncoding = "pem" )
type KeyType ¶
type KeyType string
KeyType represents the type of cryptographic key.
type Token ¶
Token represents a PASETO token with claims.
func NewToken ¶
NewToken creates a new token with the specified claims. Default claims (iat, nbf, exp) are automatically added if not provided.
func ParseToken ¶
ParseToken parses a PASETO token string using the provided key.
func (*Token) Claims ¶ added in v0.2.0
Claims returns all claims of this token in a stable order. Registered claims will be first in the order defined by RegisteredClaims, followed by custom claims ordered lexicographically by name. An error is returned if converting a registered claim value to its expected type fails.
type TokenFormat ¶
type TokenFormat string
TokenFormat represents the output format for token display.
const ( TokenFormatText TokenFormat = "text" TokenFormatJSON TokenFormat = "json" )