identity

package module
v0.0.0-...-7554954 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2019 License: Apache-2.0 Imports: 12 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

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")

Functions

This section is empty.

Types

type Claims

type Claims struct {
	jwt.StandardClaims
	UserID         string `json:"userID"`
	UserName       string `json:"userName"`
	AdditionalData map[string]interface{}
}

type IJWTService

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

type JWTResponse

type JWTResponse struct {
	Token    string `json:"token"`
	UserID   string `json:"userID"`
	UserName string `json:"userName"`
}

type JWTService

type JWTService struct {
	AuthSalt         string
	AuthSecret       string
	Issuer           string
	TimeoutInMinutes int
}

JWTService provides methods for working with JWTs in MailSlurper

func (*JWTService) CreateToken

func (s *JWTService) CreateToken(authSecret, userID, userName string, additionalData map[string]interface{}) (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, string)

GetUserFromToken retrieves the user ID and name 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