jwt

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: LGPL-2.1 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeTokenAccess  = "access_token"
	TypeTokenRefresh = "refresh_token"
)

const

Variables

This section is empty.

Functions

This section is empty.

Types

type Service

type Service struct {
	// Algo signing algorithm used for signing.
	Algo jwt.SigningMethod
	// SecretKey used for signing.
	SecretKey []byte
	// AccessKeyDuration duration (in seconds) for which the jwt access token is valid.
	AccessDuration time.Duration
	// RefreshDuration duration (in seconds) for which the jwt refresh token is valid.
	RefreshDuration time.Duration
}

Service provides a Json-Web-Token authentication implementation

func New

func New(algo, secretKey string, durations ...int) *Service

New generates new JWT service necessery for auth middleware

func (*Service) GenerateToken

func (j *Service) GenerateToken(input *TokenInput, output *TokenOutput) error

GenerateToken generates new Service token and populates it with user data

func (*Service) MWFunc

func (j *Service) MWFunc() echo.MiddlewareFunc

MWFunc makes JWT implement the Middleware interface.

func (*Service) ParseToken

func (j *Service) ParseToken(input string) (*jwt.Token, error)

ParseToken parses token from string

func (*Service) ParseTokenFromHeader

func (j *Service) ParseTokenFromHeader(c echo.Context) (*jwt.Token, error)

ParseTokenFromHeader parses token from Authorization header

type TokenInput

type TokenInput struct {
	Type   string                 `json:"type"` // refresh_token or access_token
	Claims map[string]interface{} `json:"claims"`
}

TokenInput represents the input of a token request

type TokenOutput

type TokenOutput struct {
	Token     string `json:"token"`
	ExpiresIn int    `json:"expires_in"`
}

TokenOutput represents the output of a token request

Jump to

Keyboard shortcuts

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