jwt

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 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 struct {
	// contains filtered or unexported fields
}

Authorizer handles JWT-based authorization for API requests.

func NewAuthorizer

func NewAuthorizer(jwtProvider *Provider) *Authorizer

NewAuthorizer creates a new JWT authorizer instance.

func (*Authorizer) Authorize

func (au *Authorizer) Authorize(w http.ResponseWriter, r *http.Request) (token string, usr *userModels.User, acc *accountModels.Account, err error)

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

func (*Authorizer) AuthorizerCode

func (au *Authorizer) 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
	SocealAccountID uint64 // Note: typo - consider renaming to SocialAccountID
	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