jwt

package
v0.0.0-...-4b578d8 Latest Latest
Warning

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

Go to latest
Published: May 22, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AuthHeaderKey            = "Authorization"
	BearerPrefix             = "Bearer"
	AuthCtxKey    authCtxKey = "ctx:auth-user"
)
View Source
const (
	AccessIssuer  string = "auth-access"
	RefreshIssuer string = "auth-refresh"
)

Variables

This section is empty.

Functions

func AdminOnly

func AdminOnly(next http.Handler) http.Handler

func AuthMiddleware

func AuthMiddleware(next http.Handler, parseToken tokenParser, validate claimsValidator) http.Handler

AuthMiddleware - common middleware logic.

func Authenticated

func Authenticated(next http.Handler) http.Handler

func InitJWT

func InitJWT(c *config.Jwt) error

InitJWT initializes a new jwtService.

func RefreshFlow

func RefreshFlow(next http.Handler) http.Handler

func TenantOnly

func TenantOnly(next http.Handler) http.Handler

func TenantOrAdminOnly

func TenantOrAdminOnly(next http.Handler) http.Handler

Types

type Claims

type Claims struct {
	*jwt.RegisteredClaims
	// Application-specific claims
	Role string `json:"role,omitempty"`
}

Claims represents all JWT claims used in the system.

func ParseClaimsCtx

func ParseClaimsCtx(ctx context.Context) (*Claims, int64, error)

type Service

type Service interface {
	ParseRefreshToken(token string) (*Claims, error)
	ParseAccessToken(token string) (*Claims, error)
	IssueTokenPair(
		userID int64,
		email, role string,
	) (*Tokens, error)
}

func GetService

func GetService() Service

type Tokens

type Tokens struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	ExpiresIn    int64  `json:"expires_in"`
}

Tokens holds the generated access and refresh tokens.

Jump to

Keyboard shortcuts

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