jwt

package
v0.0.0-...-f597de0 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrSignature = errors.New("Token signature invalid")

ErrSignature is returned by jwt.Service.Verify method when the token signature is invalid.

Functions

This section is empty.

Types

type CustomClaims

type CustomClaims struct {
	Username string `json:"username"`
	jwt.StandardClaims
}

CustomClaims hold the extended claims for the application. i.e. standard claims and the username

type FilePrivateKeyReader

type FilePrivateKeyReader struct {
	KeyPath string
}

FilePrivateKeyReader implements PrivateKeyReader.

func (FilePrivateKeyReader) Read

func (r FilePrivateKeyReader) Read() ([]byte, error)

Read a private key from a local file

type PrivateKeyReader

type PrivateKeyReader interface {
	Read() ([]byte, error)
}

PrivateKeyReader depicts the interface to read a private key from a location.

type Service

type Service struct {
	PrivateKeyReader PrivateKeyReader
}

Service exhibits the methods one can call on a jwt.Service. It has a PrivateKeyReader to read a private key from a location depending the implementation.

func (Service) NewToken

func (s Service) NewToken(username string) (*Token, error)

NewToken returns a new jwt.Token.

func (Service) Verify

func (s Service) Verify(tokenString string) (bool, error)

Verify a token. Returns false along with the associated error

if the private key cannot be read
if the key cannot be parsed
if the claims cannot be parsed
if the claims are not of type jwt.CustomClaims.

Returns false and jwt.ErrSignature if the token signature is invalid. Returns true if the verification is successfull.

type Token

type Token struct {
	Type        string
	AccessToken string
	ExpriresIn  time.Time
}

Token is a JWT token.

func (Token) String

func (t Token) String() string

String returns a string representation of the Token.

Jump to

Keyboard shortcuts

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