parser

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2023 License: MIT Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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