jwt

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 20, 2026 License: MIT Imports: 8 Imported by: 0

README

jwt

该目录只是对外公开的便捷转发层。

  • 面向业务代码提供 gorp/jwt 入口
  • 真实实现仍在 framework/*
  • 不在这里承载独立认证实现或新语义

Documentation

Index

Constants

View Source
const (
	ContextJWTClaimsKey   = frameworkjwt.ContextJWTClaimsKey
	ContextSubjectIDKey   = frameworkjwt.ContextSubjectIDKey
	ContextSubjectTypeKey = frameworkjwt.ContextSubjectTypeKey
)

Variables

This section is empty.

Functions

func AuthMiddleware

func AuthMiddleware(jwtSvc securitycontract.JWTService, expectedSubjectType string) transportcontract.Middleware

AuthMiddleware creates a framework HTTP middleware based on business JWT verification. AuthMiddleware 创建基于业务 JWT 的 framework HTTP 中间件。

Example:

router.Use(jwt.AuthMiddleware(jwtSvc, "user"))

func Get

Get returns the business JWT service from the container. Get 从容器获取业务 JWT 服务。

func GetOrPanic

GetOrPanic returns the business JWT service from the container and panics on failure. GetOrPanic 从容器获取业务 JWT 服务,失败 panic。

func NewService

func NewService(secret, issuer, audience string) securitycontract.JWTService

NewService creates a business JWT service. NewService 创建业务 JWT 服务。

func SecretFromConfig

func SecretFromConfig(cfg datacontract.Config) string

SecretFromConfig resolves the business JWT secret from config. SecretFromConfig 统一从配置中解析业务 JWT secret。

func SubjectIDFromContext

func SubjectIDFromContext(ctx context.Context) (int64, bool)

SubjectIDFromContext extracts the business subject id from context. SubjectIDFromContext 从 request/framework context 中提取业务主体 ID。

func SubjectIDFromRequestContext

func SubjectIDFromRequestContext(ctx context.Context) (int64, bool)

SubjectIDFromRequestContext extracts the business subject id from request context. SubjectIDFromRequestContext 从 request context 提取业务主体 ID。

func SubjectTypeFromRequestContext

func SubjectTypeFromRequestContext(ctx context.Context) (string, bool)

SubjectTypeFromRequestContext extracts the business subject type from request context. SubjectTypeFromRequestContext 从 request context 提取业务主体类型。

Types

type JWTClaims

type JWTClaims = securitycontract.JWTClaims

func ClaimsFromRequestContext

func ClaimsFromRequestContext(ctx context.Context) (*JWTClaims, bool)

ClaimsFromRequestContext extracts business JWT claims from request context. ClaimsFromRequestContext 从 request context 提取业务 JWT claims。

type JWTService

type JWTService = securitycontract.JWTService

Jump to

Keyboard shortcuts

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