Documentation ¶
Overview ¶
Package auth provides utility functions for password authentication and JWT access control.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrorIncorrectLogin = errors.New("Invalid username or password")
ErrorIncorrectLogin represents a failed login attempt.
Functions ¶
func CheckPassword ¶
CheckPassword returns true if the provided password matches the hash; else false.
Types ¶
type Claims ¶
type Claims struct {
jwt.StandardClaims
}
Claims stores the set of user claims for JWTs.
type LoginManager ¶
type LoginManager struct { DB *kvstore.KeyValueDB Token *TokenSigner }
LoginManager is an object made for managing user signin and authentication using the built-in token signing and key-value storage mechanisms (based on sqlite).
The provided methods can easily be used with the dispatch API framework by adding routes for SignupUser and AuthenticateUser.
func (*LoginManager) AuthenticateUser ¶
func (lm *LoginManager) AuthenticateUser(login UserLogin) (token string, err error)
AuthenticateUser attempts to log in an existing user with the provided credentials, returning an access token if the credentials match.
func (*LoginManager) SignupUser ¶
func (lm *LoginManager) SignupUser(login UserLogin) (token string, err error)
SignupUser creates and stores user information for the new user. Upon successful registration, the user is signed in and the new generated token is returned.
type TokenSigner ¶
type TokenSigner struct { // Issuer is the value of the issuer field in the standard claims attached // to tokens generated by this signer. Issuer string // contains filtered or unexported fields }
TokenSigner is an object providing methods for creating and validating JWTs.
func NewTokenSigner ¶
func NewTokenSigner(issuer string, secret []byte) *TokenSigner
NewTokenSigner generates a new TokenSigner object with the specified issuer and secret token.
func (*TokenSigner) CreateToken ¶
func (ts *TokenSigner) CreateToken(username string) (string, error)
CreateToken creates a JWT token for a user to use for authentication.
func (*TokenSigner) ParseToken ¶
func (ts *TokenSigner) ParseToken(tokenStr string) (*Claims, error)
ParseToken verifies a token and returns its claims.