jwt

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: Apache-2.0 Imports: 13 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Authorizer

type Authorizer[TUser user.Model, TAccount account.Model] struct {
	// contains filtered or unexported fields
}

Authorizer handles JWT-based authorization for API requests.

func NewAuthorizer

func NewAuthorizer[TUser user.Model, TAccount account.Model](jwtProvider *Provider, loader *accauth.Loader[TUser, TAccount]) *Authorizer[TUser, TAccount]

NewAuthorizer creates a new JWT authorizer instance.

func (*Authorizer[TUser, TAccount]) Authorize

func (au *Authorizer[TUser, TAccount]) Authorize(w http.ResponseWriter, r *http.Request) (token string, usr TUser, acc TAccount, err error)

Authorize validates the JWT token from the request and retrieves associated user and account data.

func (*Authorizer[TUser, TAccount]) AuthorizerCode

func (au *Authorizer[TUser, TAccount]) AuthorizerCode() string

AuthorizerCode returns the identifier for this authorizer.

type MapClaims

type MapClaims = jwt.MapClaims

MapClaims describes the Claims type that uses map[string]interface{} for JSON decoding

type Middleware

type Middleware = jwtmiddleware.JWTMiddleware

Middleware object type

type Provider

type Provider struct {
	TokenLifetime  time.Duration          // Valid time period for tokens
	Secret         string                 // Secret key for signing
	MiddlewareOpts *jwtmiddleware.Options // Middleware configuration
}

Provider manages JWT token creation and validation

func NewDefaultProvider

func NewDefaultProvider(secret string, tokenLifetime time.Duration, isDebug bool) *Provider

NewDefaultProvider creates a new JWT provider with default settings

func (*Provider) CreateToken

func (provider *Provider) CreateToken(userID, accountID, socialAccountID uint64) (string, time.Time, error)

CreateToken generates a new signed JWT token for the given user

func (*Provider) ExtractTokenData

func (provider *Provider) ExtractTokenData(token *Token) (*TokenData, error)

ExtractTokenData extracts and validates claims from a token

func (*Provider) Middleware

func (provider *Provider) Middleware() *jwtmiddleware.JWTMiddleware

Middleware returns a configured JWT middleware handler

func (*Provider) MiddlewareOptions

func (provider *Provider) MiddlewareOptions() *jwtmiddleware.Options

MiddlewareOptions returns configured middleware options with defaults

type Token

type Token = jwt.Token

Token of JWT session

type TokenData

type TokenData struct {
	UserID          uint64
	AccountID       uint64
	SocialAccountID uint64
	ExpireAt        int64
}

TokenData contains extracted token information

Jump to

Keyboard shortcuts

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