identity

package
v3.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 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 CreateTokenRequest

type CreateTokenRequest struct {
	UserID         string
	UserName       string
	AdditionalData map[string]interface{}
}

A CreateTokenRequest is used when creating a new JWT token. It contians basic information about a user, and then allows for additional data

type IJWTService

type IJWTService interface {
	CreateToken(createRequest *CreateTokenRequest) (string, error)
	GetUserFromToken(token *jwt.Token) (string, string)
	ParseToken(tokenFromHeader 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 {
	// contains filtered or unexported fields
}

JWTService provides methods for working with JWTs in MailSlurper

func NewJWTService

func NewJWTService(config *JWTServiceConfig) *JWTService

NewJWTService creates a new instance of the JWTService struct

func (*JWTService) CreateToken

func (s *JWTService) CreateToken(createRequest *CreateTokenRequest) (string, error)

CreateToken creates a new JWT token and encrypts it

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

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

ParseToken decrypts the provided token and returns a JWT token object

type JWTServiceConfig

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

JWTServiceConfig is a configuration object for initializing the JWTService struct

Jump to

Keyboard shortcuts

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