jwttoken

package
v0.0.0-...-d0a0e58 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultSecret = "" /* 154-byte string literal not displayed */

	PTAccess  PermissionType = "access"  // Access to all interfaces except the generation of access Token interface
	PTRefresh PermissionType = "refresh" // Only the generated Access Token interface can be accessed
	PTCustom  PermissionType = "custom"  // Custom, not set the ExpirationTime field

	AccessTokenDuration  = time.Hour * 1
	RefreshTokenDuration = time.Hour * 24 * 7
)

Variables

This section is empty.

Functions

func TokenSecretEncode

func TokenSecretEncode(ts *TokenSecret) (encoded string, err error)

Types

type JwtPayload

type JwtPayload struct {
	jwt.Payload
	Permission PermissionType `json:"perm"`
	Uid        string         `json:"uid"`
	ClientId   string         `json:"cid,omitempty"`
	Extend     interface{}    `json:"extend,omitempty"`
}

type KeyType

type KeyType string
const (
	KTJwtHS256 KeyType = "HS256"
	KTJwtRS256 KeyType = "RS256"
)

type PermissionType

type PermissionType string

type Token

type Token struct {
	// contains filtered or unexported fields
}

func NewToken

func NewToken(s *TokenSecret) *Token

func (*Token) GenerateJwtToken

func (t *Token) GenerateJwtToken(payload interface{}) (token string, err error)

func (*Token) VerifyJwtToken

func (t *Token) VerifyJwtToken(token string, payload interface{}) error

type TokenGenerator

type TokenGenerator struct {
	// contains filtered or unexported fields
}

func GetDefaultTokenGenerator

func GetDefaultTokenGenerator() *TokenGenerator

GetDefaultTokenGenerator return a singleton TokenGenerator with default secret

func NewTokenGenerator

func NewTokenGenerator(ts *TokenSecret) *TokenGenerator

func (*TokenGenerator) Generate

func (tg *TokenGenerator) Generate(issuer string, perm PermissionType, uid string, clientId string, extend interface{}) (token string, err error)

func (*TokenGenerator) Verify

func (tg *TokenGenerator) Verify(token string, payload *JwtPayload) (valid bool, err error)

type TokenSecret

type TokenSecret struct {
	Type       KeyType `json:"type"`
	PrivateKey []byte  `json:"private_key"`
}

func GenerateTokenSecret

func GenerateTokenSecret(kt KeyType) (ts *TokenSecret, err error)

func TokenSecretDecode

func TokenSecretDecode(encoded string) (ts *TokenSecret, err error)

Jump to

Keyboard shortcuts

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