user

package
v0.0.0-...-85dfee8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 22, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckPasswordHash

func CheckPasswordHash(password, hash string) bool

Verify password hash using bcrypt

func GetJwtClaims

func GetJwtClaims(tokenString string, tokenType string) (claimValues models.JwtClaims, err error)

Accepts a JSON Web Token string, the tokenType ("refresh" or "access), and returns the token's claim values mapped to a JwtClaims struct.

func HashPassword

func HashPassword(password string) (string, error)

Hash password using bcrypt

func Login

func Login(res http.ResponseWriter, req *http.Request)

Verify that provided user credentials are correct. If yes, generate two JSON Web Tokens. One token ("access") is for accessing API endpoints and the other ("refresh") is for refreshing access tokens. Return the JWT strings as values in the access_token and refresh_token cookies.

func Logout

func Logout(res http.ResponseWriter, req *http.Request)

Logs out user by deleting their access_token and refresh_token cookies. The associated JWTs are also added to a blocklist until their timeout period has finished.

func RefreshJwt

func RefreshJwt(res http.ResponseWriter, req *http.Request)

Generates a new access token if provided with a valid refresh token. Returns the new access token in the access_token cookie.

func Register

func Register(res http.ResponseWriter, req *http.Request)

Registers a new user by creating a new entry in the "users" table.

func VerifyJwt

func VerifyJwt(res http.ResponseWriter, req *http.Request)

Takes a JWT string from the query parameter "token" (?token=ABCD1234) and attemps to return the JWT's claim values. It will only attempt to validate access_token values. Can be used by other services to validate that the user is authenticated and retrieve their userId. This handler function should be used on a route that is inaccessible to outside users.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL