jwtservice

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	USAGE_AUTH    = "auth"
	USAGE_REFRESH = "refresh"
)

Variables

View Source
var (
	// ProviderProductionSet provides a new JWTServiceImpl for use in production.
	ProviderProductionSet = wire.NewSet(Provide, wire.Bind(new(JWTService), new(*JWTServiceImpl)), Cfg)
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Issuer          string
	SigningKey      string
	Duration        time.Duration
	RefreshDuration time.Duration
}

Config contains the parameters for configuring a JWTService.

func Cfg

func Cfg(v *viper.Viper) (*Config, error)

Cfg provides a new Config using values from a Viper.

type InvalidTokenPair

type InvalidTokenPair struct{}
var (
	ErrInvalidTokenPair *InvalidTokenPair = &InvalidTokenPair{}
)

func (InvalidTokenPair) Error

func (i InvalidTokenPair) Error() string

func (InvalidTokenPair) Is

func (i InvalidTokenPair) Is(tgt error) bool

type JWTService

type JWTService interface {
	GenerateAuthToken(user domain.User) (*domain.AuthToken, error)
	GenerateRefreshToken(user domain.User, authToken domain.AuthToken, parentToken *domain.RefreshToken) (*domain.RefreshToken, error)
	ValidateAuthToken(token domain.TokenValue) (domain.AuthToken, error)
	ValidateRefreshToken(token domain.TokenValue) (domain.RefreshToken, error)
}

JWTService is a service for generating and validating JWTs.

type JWTServiceImpl

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

JWTServiceImpl is an implementation of a JWTService.

func Provide

func Provide(config *Config) *JWTServiceImpl

Provide returns a new JWTService with the specified config.

func (*JWTServiceImpl) GenerateAuthToken

func (j *JWTServiceImpl) GenerateAuthToken(user domain.User) (*domain.AuthToken, error)

GenerateToken creates a JWT for the specified User and returns the token.

func (*JWTServiceImpl) GenerateRefreshToken

func (j *JWTServiceImpl) GenerateRefreshToken(user domain.User, authToken domain.AuthToken, parentToken *domain.RefreshToken) (*domain.RefreshToken, error)

GenerateRefreshToken creates a Refresh JWT for the specified User and returns the token.

func (*JWTServiceImpl) ValidateAuthToken

func (j *JWTServiceImpl) ValidateAuthToken(token domain.TokenValue) (domain.AuthToken, error)

ValidateAuthToken validates the given TokenValue as an AuthToken. If the token is valid, the token is returned as an AuthToken. Otherwise, a nil token is returned along with an error.

func (*JWTServiceImpl) ValidateRefreshToken

func (j *JWTServiceImpl) ValidateRefreshToken(token domain.TokenValue) (domain.RefreshToken, error)

ValidateRefreshToken validates the given TokenValue as a RefreshToken. If the token is valid, the token is returned as a RefreshToken. Otherwise, a nil token is returned along with an error.

Jump to

Keyboard shortcuts

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