auth

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func VerifyJWT

func VerifyJWT(token string, jwtSecret []byte) (bool, error)

VerifyJWT returns true if a JWT is valid, false otherwise

Types

type Claims

type Claims struct {
	UID       string `json:"uid"`
	FirstName string `json:"first_name"`
	jwt.StandardClaims
}

Claims is a struct that will be encoded to a JWT. We add jwt.StandardClaims as an embedded type, to provide fields like expiry time

func GetJWTClaims

func GetJWTClaims(token string, jwtSecret []byte) (Claims, error)

GetJWTClaims returns claims associated to a JWT

type JWT

type JWT struct {
	Token   string
	Expires time.Time
}

func Authenticate

func Authenticate(email, password string, jwtSecret []byte) (JWT, error)

Authenticate receives an email and a password, compares the hash with the one in database. If they match, it creates a session token, stores it in the Sessions map and returns the sessionToken to the caller

Jump to

Keyboard shortcuts

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