Documentation
¶
Index ¶
- Variables
- type Claims
- type IJWTService
- type JWTResponse
- type JWTService
- func (s *JWTService) CreateToken(authSecret, userID, userName string, additionalData map[string]interface{}) (string, error)
- func (s *JWTService) DecryptToken(token string) (string, error)
- func (s *JWTService) EncryptToken(token string) (string, error)
- func (s *JWTService) GetUserFromToken(token *jwt.Token) (string, string)
- func (s *JWTService) IsTokenValid(token *jwt.Token) error
- func (s *JWTService) Parse(tokenFromHeader, authSecret string) (*jwt.Token, error)
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 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 JWTService ¶
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
Click to show internal directories.
Click to hide internal directories.