Documentation
¶
Index ¶
- Constants
- func AuthMiddleware(jwtSvc securitycontract.JWTService, expectedSubjectType string) transportcontract.Middleware
- func Get(c runtimecontract.Container) (securitycontract.JWTService, error)
- func GetOrPanic(c runtimecontract.Container) securitycontract.JWTService
- func NewService(secret, issuer, audience string) securitycontract.JWTService
- func SecretFromConfig(cfg datacontract.Config) string
- func SubjectIDFromContext(ctx context.Context) (int64, bool)
- func SubjectIDFromRequestContext(ctx context.Context) (int64, bool)
- func SubjectTypeFromRequestContext(ctx context.Context) (string, bool)
- type JWTClaims
- type JWTService
Constants ¶
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 ¶
func Get(c runtimecontract.Container) (securitycontract.JWTService, error)
Get returns the business JWT service from the container. Get 从容器获取业务 JWT 服务。
func GetOrPanic ¶
func GetOrPanic(c runtimecontract.Container) securitycontract.JWTService
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 ¶
SubjectIDFromContext extracts the business subject id from context. SubjectIDFromContext 从 request/framework context 中提取业务主体 ID。
func SubjectIDFromRequestContext ¶
SubjectIDFromRequestContext extracts the business subject id from request context. SubjectIDFromRequestContext 从 request context 提取业务主体 ID。
Types ¶
type JWTClaims ¶
type JWTClaims = securitycontract.JWTClaims
type JWTService ¶
type JWTService = securitycontract.JWTService