Categorygithub.com/dangersalad/go-user
modulepackage
0.9.0
Repository: https://github.com/dangersalad/go-user.git
Documentation: pkg.go.dev

# README

user

Go Report Card Go Doc Release

# Functions

CheckTokenString verifies that a JWT token string is valid.
CheckUserPass uses the AuthConfig to extract and check a username and password from a provided authorization header string.
ContextClaims returns the JWT claims stored on the context.
ContextToken returns the JWT token stored on the context.
ExtractClaims gets the claims from a given token string.
ExtractDefaultClaims gets the default claims from a given token string.
ExtractUserPass extracts a username or password from a request.
GetKey returns the key for signing JWT tokens.
GetTokenExpireTime returns a valid expire time in hours.
LoginHandlerFunc returns an http.HandlerFunc that logs in a user with either a username/password or a token in the Authorization header and returns a 201 with the user's token in a cookie.
MakeCookie makes a cookie for use with http.SetCookie from a given token string, origin and hostname.
MakePasswordHash makes a bcrypt password hash for the given password.
MakeTokenString makes a JWT token string from a given set of claims.
PasswordIsValid checks the password and a provided hash.
RequestClaims returns the JWT claims stored on the request context.
RequestToken returns the JWT token stored on the request context.
SetLogger sets a logger on the package that will print messages.
SetToken takes JWT claims and generates a cookie, which is then set on the given http.ResponseWriter.
TokenCheckHandler returns an http.Handler that checks cookie for a JWT, parses it and sets the claims to the request context.

# Constants

EnvKeyJWTKey is the environment key containing the key for JWT hashing.

# Variables

ContextKeyClaims is the context key for claims.
ContextKeyToken is the context key for the token string.

# Structs

AuthConfig is the configuration for auth check handler.
Bypass represents bypasses for certain methods and routes.
Claims are the default JWT claims.

# Interfaces

Auther is an interface for a "user" that can auth.
AuthErr is the interface to get more info on an auth error.