Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var JWTClaimUsername = "username"
JWTClaimUsername is claims key which holds user's username.
var JWTSigningMethod = jwt.SigningMethodHS256
JWTSigningMethod is a signing method used to sign JWT claims.
Functions ¶
This section is empty.
Types ¶
type DefaultJWTAuthenticator ¶
type DefaultJWTAuthenticator struct {
// contains filtered or unexported fields
}
DefaultJWTAuthenticator is the default JWT authenticator.
func NewJWTAuthenticator ¶
func NewJWTAuthenticator(secretKey string, tokenTTL time.Duration) *DefaultJWTAuthenticator
NewJWTAuthenticator creates a new instance of DefaultJWTAuthenticator and returns pointer to it.
func (*DefaultJWTAuthenticator) CreateToken ¶
CreateToken generates a new JWT and returns its string representation and expiration timestamp.
func (*DefaultJWTAuthenticator) VerifyToken ¶
func (a *DefaultJWTAuthenticator) VerifyToken(tokenString string) (jwt.MapClaims, error)
VerifyToken verifies that JWT token is valid and not expired, returns claims it contains.
type DefaultPasswordAuthenticator ¶
type DefaultPasswordAuthenticator struct {
// contains filtered or unexported fields
}
DefaultPasswordAuthenticator represents password hashing and validation authority.
func NewPasswordAuthenticator ¶
func NewPasswordAuthenticator(bcryptCost int) *DefaultPasswordAuthenticator
NewPasswordAuthenticator creates a new instance of DefaultPasswordAuthenticator and returns pointer to it.
func (*DefaultPasswordAuthenticator) HashPassword ¶
func (d *DefaultPasswordAuthenticator) HashPassword(password string) (string, error)
HashPassword returns hash of a given password.
func (*DefaultPasswordAuthenticator) VerifyPassword ¶
func (d *DefaultPasswordAuthenticator) VerifyPassword(password string, hash string) (bool, error)
VerifyPassword returns true if a given password matches with a given hash.
type JWTAuthenticator ¶
type JWTAuthenticator interface { // CreateToken generates a new JWT and returns its string representation and expiration timestamp. // todo: should `expires` be returned and is it necessary for a user? CreateToken(username string) (token string, expires time.Time, err error) // VerifyToken verifies that JWT token is valid and not expired, returns claims it contains. VerifyToken(token string) (jwt.MapClaims, error) }
JWTAuthenticator is an interface for a JWT authenticator: it can create and verify tokens.