Documentation ¶
Index ¶
- Constants
- Variables
- type Config
- type InvalidTokenPair
- type JWTService
- type JWTServiceImpl
- func (j *JWTServiceImpl) GenerateAuthToken(user domain.User) (*domain.AuthToken, error)
- func (j *JWTServiceImpl) GenerateRefreshToken(user domain.User, authToken domain.AuthToken, parentToken *domain.RefreshToken) (*domain.RefreshToken, error)
- func (j *JWTServiceImpl) ValidateAuthToken(token domain.TokenValue) (domain.AuthToken, error)
- func (j *JWTServiceImpl) ValidateRefreshToken(token domain.TokenValue) (domain.RefreshToken, error)
Constants ¶
const ( USAGE_AUTH = "auth" USAGE_REFRESH = "refresh" )
Variables ¶
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.
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 ¶
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.