token

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrTokenInvalid = errors.New("couldn't handle this token")

Functions

func GetBearerToken added in v0.2.0

func GetBearerToken(req *http.Request) string

GetBearerToken Get bearer token from request header.

func Init

func Init(secretKey string, ttl uint)

func SetIssuer added in v0.4.0

func SetIssuer(issuer string)

Types

type Client added in v0.4.0

type Client struct {
	SecretKey string
	TTL       uint
	Issuer    string
}

func New added in v0.4.0

func New(secretKey string, ttl uint) *Client

func (*Client) Parse added in v0.4.0

func (client *Client) Parse(tokenString string) (*CustomClaims, error)

Parse token by secret key.

func (*Client) SetIssuer added in v0.4.0

func (client *Client) SetIssuer(issuer string) *Client

func (*Client) Sign added in v0.4.0

func (client *Client) Sign(subject string, info any) (*Response, error)

Sign a token by jwt secret.

type CustomClaims

type CustomClaims struct {
	Info any `json:"info"`
	jwt.RegisteredClaims
}

func Parse

func Parse(tokenString string) (*CustomClaims, error)

Parse token by secret key.

func ParseRequest

func ParseRequest(req *http.Request) (*CustomClaims, error)

ParseRequest Parse token from request header.

func ParseToken added in v0.3.4

func ParseToken(req *http.Request, token string) (*CustomClaims, error)

ParseToken Parse given token.

type Response

type Response struct {
	AccessToken string    `json:"accessToken"`
	ExpiresAt   time.Time `json:"expiresAt"`
}

func Sign

func Sign(subject string, info any) (*Response, error)

Sign a token by jwt secret.

Jump to

Keyboard shortcuts

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