Documentation
¶
Index ¶
- func AuthRequired() gin.HandlerFunc
- func CheckPassword(password, hash string) bool
- func ClearAuthCookies(c *gin.Context)
- func GenerateRandomToken() (string, error)
- func GenerateTokenPair(userID string) (accessToken string, refreshToken string, err error)
- func GetJWTSecret() string
- func HashPassword(password string) (string, error)
- func HashRefreshToken(token string) string
- func Login(c *gin.Context)
- func Logout(c *gin.Context)
- func Me(c *gin.Context)
- func Refresh(c *gin.Context)
- func Register(c *gin.Context)
- func SetAuthCookies(c *gin.Context, accessToken, refreshToken string)
- func ValidateEmail(email string) bool
- func ValidateRefreshToken(tokenString string) (string, error)
- type Claims
- type LoginRequest
- type RegisterRequest
- type User
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AuthRequired ¶
func AuthRequired() gin.HandlerFunc
AuthRequired is a middleware that validates JWT tokens from cookies
func CheckPassword ¶
CheckPassword compares a password with its hash
func ClearAuthCookies ¶
ClearAuthCookies clears authentication cookies
func GenerateRandomToken ¶
GenerateRandomToken generates a secure random token for refresh tokens
func GenerateTokenPair ¶
GenerateTokenPair creates access and refresh tokens for a user
func GetJWTSecret ¶
func GetJWTSecret() string
GetJWTSecret retrieves the JWT secret from environment
func HashPassword ¶
HashPassword hashes a password using bcrypt
func HashRefreshToken ¶
HashRefreshToken creates a SHA256 hash of the refresh token for database storage
func SetAuthCookies ¶
SetAuthCookies sets HTTP-only authentication cookies
func ValidateEmail ¶
ValidateEmail checks if email format is valid
func ValidateRefreshToken ¶
ValidateRefreshToken validates a refresh token and returns the user ID
Types ¶
type Claims ¶
type Claims struct {
UserID string `json:"user_id"`
jwt.RegisteredClaims
}
JWT Claims structure
func ValidateAccessToken ¶
ValidateAccessToken validates an access token and returns the claims