jwt

package
v0.0.0-...-5d7ca49 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidIssuer error = fmt.Errorf("Invalid issuer")
View Source
var ErrInvalidToken error = fmt.Errorf("Invalid token")
View Source
var ErrInvalidUser error = fmt.Errorf("Invalid user")
View Source
var ErrTokenMissingClaims error = fmt.Errorf("Token is missing claims")
View Source
var JWTIssuer string = "mailslurper"

Functions

This section is empty.

Types

type Claims

type Claims struct {
	jwt.StandardClaims
	User string `json:"user"`
}

type IJWTService

type IJWTService interface {
	CreateToken(authSecret, user string) (string, error)
	DecryptToken(token string) (string, error)
	EncryptToken(token string) (string, error)
	GetUserFromToken(token *jwt.Token) string
	Parse(tokenFromHeader, authSecret string) (*jwt.Token, error)
	IsTokenValid(token *jwt.Token) error
}

type JWTService

type JWTService struct {
	Config *mailslurper.Configuration
}

JWTService provides methods for working with JWTs in MailSlurper

func (*JWTService) CreateToken

func (s *JWTService) CreateToken(authSecret, user string) (string, error)

CreateToken creates a new JWT token for use in MailSlurper services

func (*JWTService) DecryptToken

func (s *JWTService) DecryptToken(token string) (string, error)

DecryptToken takes a Base64 encoded token which has been encrypted using AES-256 encryption. This returns the unencoded, unencrypted token

func (*JWTService) EncryptToken

func (s *JWTService) EncryptToken(token string) (string, error)

EncryptToken takes a token string, encrypts it using AES-256, then encodes it in Base64.

func (*JWTService) GetUserFromToken

func (s *JWTService) GetUserFromToken(token *jwt.Token) string

GetUserFromToken retrieves the user from the claims in a JWT token

func (*JWTService) IsTokenValid

func (s *JWTService) IsTokenValid(token *jwt.Token) error

IsTokenValid returns an error if there are any issues with the provided JWT token. Possible issues include:

  • Missing claims
  • Invalid token format
  • Invalid issuer
  • User doesn't have a corresponding entry in the credentials table

func (*JWTService) Parse

func (s *JWTService) Parse(tokenFromHeader, authSecret string) (*jwt.Token, error)

Parse decrypts the provided token and returns a JWT token object

Jump to

Keyboard shortcuts

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