utils

package
v0.0.0-...-be022e4 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2020 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const JWTAccessKey = "JWT_ACCESS_KEY"

JWTAccessKey ust be set in .env

View Source
const JWTAuthCodeKey = "JWT_AUTHORIZATION_CODE_KEY"

JWTAuthCodeKey must be set in .env

View Source
const JWTRefreshKey = "JWT_REFRESH_KEY"

JWTRefreshKey must be set in .env

Variables

This section is empty.

Functions

func CheckPasswordHash

func CheckPasswordHash(password, hash string) bool

CheckPasswordHash checks hash of password

func ExtractToken

func ExtractToken(r *http.Request) *string

ExtractToken extracts token from Bearer

func HashPassword

func HashPassword(pass string) ([]byte, error)

HashPassword hashes password with bcrypt

func IsEmailValid

func IsEmailValid(e string) bool

IsEmailValid checks if the email provided passes the required structure and length.

Types

type TokenClaims

type TokenClaims struct {
	jwt.StandardClaims
}

TokenClaims is claims for jwt token

type TokenDetails

type TokenDetails struct {
	Token  *jwt.Token
	Claims TokenClaims
}

TokenDetails combines token string and claims

func CreateAccessToken

func CreateAccessToken() (*TokenDetails, error)

CreateAccessToken creates acces token and returns it

func CreateAuthorizationCode

func CreateAuthorizationCode(userID primitive.ObjectID) (*TokenDetails, error)

CreateAuthorizationCode creates authorization code

func CreateRefreshToken

func CreateRefreshToken() (*TokenDetails, error)

CreateRefreshToken creates acces token and returns it

func VerifyToken

func VerifyToken(strtoken string, secretEnv string) (*TokenDetails, error)

VerifyToken verifyes jwt token, secretEnv must be some enviroent variable

type TokenPair

type TokenPair struct {
	AccessToken  TokenDetails
	RefreshToken TokenDetails
}

TokenPair combins both access token and refresh token

func CreateTokenPair

func CreateTokenPair() (*TokenPair, error)

CreateTokenPair creates accessToken and refreshToken

Jump to

Keyboard shortcuts

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