auth

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

internal/auth/auth.go

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBadRequest              = errors.New("bad request")
	ErrTokenMalformed          = errors.New("malformed token")
	ErrTokenExpired            = errors.New("token is expired or not valid yet")
	ErrTokenInvalid            = errors.New("invalid token")
	ErrTokenClaimsInvalid      = errors.New("invalid token claims")
	ErrUnauthorized            = errors.New("unauthorized")
	ErrInternalServer          = errors.New("authorization error")
	ErrForbidden               = errors.New("invalid api key")
	ErrUnexpectedSigningMethod = errors.New("unexpected token signing method")
)

Functions

func CheckPasswordHash

func CheckPasswordHash(password, hash string) bool

CheckPasswordHash compares a plaintext password with a stored bcrypt hash

func GenerateJWT

func GenerateJWT(userID string, jwtSecret string, jwtExpiration time.Duration) (string, error)

GenerateJWT creates a signed JWT string for a given userID

func HashPassword

func HashPassword(password string) (string, error)

HashPassword generates a bcrypt hash for the given password

func ValidateJWT

func ValidateJWT(tokenString string, jwtSecret string) (string, error)

ValidateJWT parses and validates a JWT string, returning the UserID if valid.

Types

This section is empty.

Jump to

Keyboard shortcuts

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