File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -16,6 +16,14 @@ API_KEY_GENERATE_PREFIX: str
1616
1717## 使用方式
1818
19+ ### 新版本
20+
21+ 自 fba v1.13.3 版本起,安装后将自动应用
22+
23+ ### 老版本
24+
25+ 需要手动替换中间件:
26+
1927编辑 ` backend/core/registrar.py ` ,替换 JWT 认证中间件:
2028
2129``` python
Original file line number Diff line number Diff line change 1+ from backend .plugin .api_key .middleware import JwtApiKeyAuthMiddleware
2+ from backend .plugin .patching import replace_middleware
3+ from fastapi import FastAPI
4+ from starlette .middleware .authentication import AuthenticationMiddleware
5+
6+
7+ def setup (app : FastAPI ) -> None :
8+ # 替换中间件为插件自定义的中间件
9+ replace_middleware (
10+ app ,
11+ AuthenticationMiddleware ,
12+ AuthenticationMiddleware ,
13+ backend = JwtApiKeyAuthMiddleware (),
14+ on_error = JwtApiKeyAuthMiddleware .auth_exception_handler ,
15+ )
Original file line number Diff line number Diff line change 1- """
2- 扩展的 JWT 认证中间件,支持 API Key 认证
3-
4- 使用方式:
5- Authorization: Bearer <jwt_token> # JWT 认证
6- Authorization: Bearer fba_xxxxx # API Key 认证(以 fba_ 开头)
7- """
8-
91from fastapi import Request
102from starlette .authentication import AuthCredentials
113
You can’t perform that action at this time.
0 commit comments