token

package
v0.0.0-...-6a4a312 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTokenExpired declares a token as expired and invalid.
	ErrTokenExpired = errors.New("token already expired")
)

Functions

func Authed

func Authed(
	secret string,
	exp time.Duration,
	ident string,
	login string,
	email string,
	name string,
	admin bool,
) (string, error)

Authed generates a new authenticated token.

Types

type Claims

type Claims struct {
	Ident string `json:"ident"`
	Login string `json:"login"`
	Email string `json:"email"`
	Name  string `json:"name"`
	Admin bool   `json:"admin"`
	jwt.RegisteredClaims
}

Claims defines all required custom claims.

func Verify

func Verify(secret, token string) (*Claims, error)

Verify simply tries to verify a given token.

type Result

type Result struct {
	Token     string
	ExpiresAt time.Time
}

Result represents to token to the outer world for HTTP responses.

type Token

type Token struct {
	Text      string
	ExpiresAt time.Time
}

Token is internally used to differ between the kinds of tokens.

func New

func New(text string) *Token

New initializes a new simple token of a specified kind.

func Parse

func Parse(cookie, secret string) (*Token, error)

Parse can parse the token directly without a request.

func (*Token) Expiring

func (t *Token) Expiring(secret string, exp time.Duration) (*Result, error)

Expiring signs a token that maybe expires.

func (*Token) Unlimited

func (t *Token) Unlimited(secret string) (*Result, error)

Unlimited signs a token the never expires.

Jump to

Keyboard shortcuts

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