jwt

package module
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2020 License: MIT Imports: 4 Imported by: 0

README

covidtrace/jwt

JWT is a simplified wrapper around jwt-go that is used by COVID Trace for issuing and verifying JWT tokens. Token claims include a covidtrace:hash identifier and a covidtrace:refreshed count of the number of times a token has been refreshed.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Claims

type Claims struct {
	Hash       string `json:"covidtrace:hash,omitempty"`
	Identifier string `json:"covidtrace:identifier,omitempty"`
	Refreshed  int    `json:"covidtrace:refreshed"`
	Role       string `json:"covidtrace:role,omitempty"`
	jwt.StandardClaims
}

Claims represents the JWT claims covidtrace cares about

type Issuer

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

Issuer is the core covidtrace/jwt type. It exposes methods to issue and verify tokens.

func NewIssuer

func NewIssuer(key []byte, iss, aud string, dur time.Duration) *Issuer

NewIssuer returns, well, a new `Issuer`

func (*Issuer) Claims

func (i *Issuer) Claims(hash string, refresh int, identifier, role string) *Claims

Claims constructs a new Claims object, filling details in from i

func (*Issuer) Copy added in v0.3.2

func (i *Issuer) Copy() *Issuer

Copy returns a copy of `Issuer`

func (*Issuer) Token

func (i *Issuer) Token(hash string, refresh int, identifier, role string) (string, error)

Token handles generating a signed JWT token with the given `hash` and `refresh` count

func (*Issuer) Validate

func (i *Issuer) Validate(signedString string) (*Claims, error)

Validate handles ensuring `signedString` is a valid JWT issued by this issuer. It returns the `hash` and `refreshed` claims, or an `error` if the token is invalid

func (*Issuer) WithAud added in v0.3.2

func (i *Issuer) WithAud(aud string) *Issuer

WithAud returns a copy of `Issuer` with `aud` overwritten

func (*Issuer) WithDur added in v0.3.3

func (i *Issuer) WithDur(dur time.Duration) *Issuer

WithDur returns a copy of `Issuer` with `dur` overwritten

Jump to

Keyboard shortcuts

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