parser

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package to verify tokens

Index

Constants

View Source
const (
	// Environment variable to point to path of the public key file
	EnvPublicKeyPath = "PUBLIC_KEY_PATH"
)

Variables

View Source
var (
	// Token could not be recognized in authorizationString
	ErrTokenNotFound = errors.New("token not found")
	// Claim doesn't match content from token
	ErrClaimCouldNotBeParsed = errors.New("claim could not be parsed")
	// Token is not valid. Maybe it is expired or doesn't match the public key
	ErrTokenNotValid = errors.New("token is not valid")
	// Public key from environment variable PUBLIC_KEY_PATH couldn't be read
	ErrWhileReadingKey = errors.New("error while reading public key")
	// Public key seams to not have the valid format
	ErrWhileParsingKey = errors.New("error while parsing public key")
)

Functions

This section is empty.

Types

type JWTParser

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

Struct to parse and validate jwt tokens

func (*JWTParser) ParseToken

func (parser *JWTParser) ParseToken(authorizationString string) (*adapter.Claims, error)

Checks if the bearer token is valid and returns its content as a claim

type ParseTokenRecord added in v0.3.0

type ParseTokenRecord struct {
	AuthorizationString string
}

type ParseTokenResponse added in v0.3.0

type ParseTokenResponse struct {
	Claim *adapter.Claims
	Err   error
}

type Parser

type Parser interface {
	ParseToken(authorizationString string) (*adapter.Claims, error)
}

Interface fo pars and validate tokens

func NewJWTParser

func NewJWTParser() (Parser, error)

Constructor to create jwt parser. public key path have to be set under environment variable PUBLIC_KEY_PATH

type ParserMock added in v0.3.0

type ParserMock struct {
	ParseTokenRecordArray   []*ParseTokenRecord
	ParseTokenResponseArray []*ParseTokenResponse
}

func (*ParserMock) ParseToken added in v0.3.0

func (mock *ParserMock) ParseToken(authorizationString string) (*adapter.Claims, error)

Jump to

Keyboard shortcuts

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