jwtauth

package
v0.0.0-...-7e08af6 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2018 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var StrictMode = false

StrictMode is a global config if true, any token without exp will be rejected

Functions

func ParsePublicKey

func ParsePublicKey(pem []byte) (interface{}, error)

ParsePublicKey tries to parse rsa, ecdsa public key in PEM format from bytes

func ReadPublicKeyFile

func ReadPublicKeyFile(filepath string) (interface{}, error)

ReadPublicKeyFile tries to parse rsa, ecdsa public key in PEM format in file

Types

type JWTAuth

type JWTAuth struct {
	PublicKeys []KeyProvider
	// contains filtered or unexported fields
}

JWTAuth implements server.Authentication interface

func (*JWTAuth) Check

func (auth *JWTAuth) Check(c server.ClientAuthentication) (verified bool)

Check returns true if connection is valid

func (*JWTAuth) Debugf

func (auth *JWTAuth) Debugf(format string, v ...interface{})

Debugf for debug log

func (*JWTAuth) Errorf

func (auth *JWTAuth) Errorf(format string, v ...interface{})

Errorf for error logs

func (*JWTAuth) GetUser

func (auth *JWTAuth) GetUser(token *Token) *server.User

GetUser extract user from given token

func (*JWTAuth) SetLogger

func (auth *JWTAuth) SetLogger(logger Logger)

SetLogger set logger

func (*JWTAuth) Verify

func (auth *JWTAuth) Verify(uToken string, claims jwt.Claims) (token *jwt.Token, err error)

Verify will return a parsed token if it passes validation, or an error if any part of the token fails validation. Possible errors include malformed tokens, unknown/unspecified signing algorithms, missing secret key, tokens that are not valid yet (i.e., 'nbf' field), tokens that are expired, and tokens that fail signature verification (forged)

type KeyProvider

type KeyProvider interface {
	PublicKey() (interface{}, error)
}

KeyProvider is interface to provide public keys

func NewLazyPublicKeyFileProvider

func NewLazyPublicKeyFileProvider(value string) (KeyProvider, error)

NewLazyPublicKeyFileProvider returns a new lazy public key proivder from file

func NewPublicKeyProvider

func NewPublicKeyProvider(pem []byte) (KeyProvider, error)

NewPublicKeyProvider returns a new public key provider parsed from PEM formatted bytes

type Logger

type Logger interface {
	// Log an error
	Errorf(format string, v ...interface{})

	// Log a debug statement
	Debugf(format string, v ...interface{})
}

Logger interface compatible with NATS Server

type Token

type Token struct {
	Subject     string              `json:"sub"`
	ExpiresAt   *int64              `json:"exp,omitempty"`
	User        string              `json:"user,omitempty"`
	Name        string              `json:"name,omitempty"`
	Permissions *server.Permissions `json:"permissions,omitempty"`
}

Token is accept model token should match

func (Token) Valid

func (u Token) Valid() error

Valid lets us use the user info as Claim for jwt-go. It checks the token expiry.

Jump to

Keyboard shortcuts

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