tokener

package module
v0.0.0-...-22c6e00 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2020 License: Apache-2.0 Imports: 11 Imported by: 0

README

Neuron JWT Tokener

This repository contains Neuron auth.Tokener implementation using JWT token.

More information about JWT token: jwt.io

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessClaims

type AccessClaims struct {
	Account auth.Account `json:"account"`
	Claims
}

AccessClaims is the jwt claims implementation that keeps the accountID stored in given token.

func (*AccessClaims) GetAccount

func (c *AccessClaims) GetAccount() auth.Account

GetAccount implements auth.AccessClaims interface.

type Claims

type Claims struct {
	RevokedAt int64 `json:"revoked_at"`
	jwt.StandardClaims
}

Claims is the common claims base for both AccessClaims and RefreshClaims. It's validation returns neuron errors, and allows to check if the token was revoked.

func (*Claims) ExpiresIn

func (c *Claims) ExpiresIn() int64

ExpiresIn implements auth.Claims.

func (*Claims) Subject

func (c *Claims) Subject() string

Subject returns the subject of the token.

func (*Claims) Valid

func (c *Claims) Valid() error

Valid implements jwt.Claims and auth.Claims.

type StoreToken

type StoreToken struct {
	MappedTokens []string   `json:"mapped_tokens"`
	RevokedAt    *time.Time `json:"is_revoked"`
	ExpiresAt    time.Time  `json:"expires_at"`
}

StoreToken is the token's store value.

type Tokener

type Tokener struct {
	Parser  jwt.Parser
	Store   store.Store
	Options auth.TokenerOptions
	// contains filtered or unexported fields
}

Tokener is neuron auth.Tokener implementation for the jwt.Token. It allows to store and inspect token encrypted using HMAC, RSA and ECDSA algorithms. This structure requires store.Store to keep the revoked tokens values. For production ready services don't use in-memory default store.

func New

func New(options ...auth.TokenerOption) (*Tokener, error)

New creates new Tokener with provided 'options'.

func (*Tokener) InspectToken

func (t *Tokener) InspectToken(ctx context.Context, token string) (auth.Claims, error)

InspectToken inspects given token string and returns provided claims.

func (*Tokener) RevokeToken

func (t *Tokener) RevokeToken(ctx context.Context, token string) error

RevokeToken invalidates provided 'token'.

func (*Tokener) Token

func (t *Tokener) Token(ctx context.Context, account auth.Account, options ...auth.TokenOption) (auth.Token, error)

Token creates an auth.Token from provided options.

Jump to

Keyboard shortcuts

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