auth

package
v0.44.5 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Authentication logic and JWT operations package.

Index

Constants

View Source
const (
	ACCESS_TOKEN  = "access-token"
	REFRESH_TOKEN = "refresh-token"
)

Variables

This section is empty.

Functions

func AuthMiddleware

func AuthMiddleware(next http.Handler) http.Handler

The very authentication middleware entrypoint.

func NewAccessToken

func NewAccessToken(claims UserClaims, secret string) (string, error)

NewAccessToken generates a new signed access token.

func NewRefreshToken

func NewRefreshToken(claims jwt.StandardClaims, secret string) (string, error)

NewRefreshToken generates a new signed refresh token.

func ParseRefreshToken

func ParseRefreshToken(refreshToken string, secret string) *jwt.StandardClaims

ParseRefreshToken decodes the refreshCookie value to get the StandardClaims payload.

func Router

func Router() chi.Router

Types

type AuthUser added in v0.43.7

type AuthUser struct {
	// Nickname is the user's very username.
	Nickname string `json:"nickname"`

	// Passphrase is a legacy format converted to string from a raw byte stream
	// (do not use anymore as this will be removed in future versions).
	Passphrase string `json:"passphrase"`

	// PassphraseHex is a hexadecimal representation of a passphrase (a SHA-512 checksum).
	// Use 'echo $PASS | sha512sum' for example to get the hex format.
	PassphraseHex string `json:"passphrase_hex"`
}

type UserClaims

type UserClaims struct {
	Nickname string `json:"nickname"`
	jwt.StandardClaims
}

UserClaims is a generic structure for a personal user's (access) token.

func ParseAccessToken

func ParseAccessToken(accessToken string, secret string) *UserClaims

ParseAccessToken decodes the accessCookie value to get the UserClaims payload.

Jump to

Keyboard shortcuts

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