File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- # API Key 插件
1+ # API Key
22
3- 用户自定义 API Key 管理插件,允许用户生成 、管理和使用 API Key 进行接口认证。
3+ 用户自定义 API Key 管理,支持生成 、管理和使用 API Key 进行接口认证
44
5- ## 配置
5+ ## 全局配置
66
77在 ` backend/core/conf.py ` 中添加以下内容:
88
9- ```
9+ ``` python
1010# #################################################
1111# [ Plugin ] api_key
1212# #################################################
13+ # 基础配置
1314API_KEY_GENERATE_PREFIX : str = ' fba-'
1415```
1516
16- ## 使用方法
17-
18- ### 2. 替换 JWT 认证中间件
17+ ## 使用方式
1918
20- 编辑 ` backend/core/registrar.py ` :
19+ 编辑 ` backend/core/registrar.py ` ,替换 JWT 认证中间件 :
2120
2221``` python
2322# 原来的导入
@@ -40,24 +39,3 @@ app.add_middleware(
4039 on_error = JwtApiKeyAuthMiddleware.auth_exception_handler,
4140)
4241```
43-
44- ## 认证流程
45-
46- ``` mermaid
47- flowchart TD
48- A[Authorization: Bearer token] --> B[token.startswith 'fba-' ?]
49- B -->|Yes| C[API Key 认证]
50- B -->|No| D[JWT Token 认证]
51- C --> I[RBAC 权限校验]
52- D --> I
53- ```
54-
55- ## 权限控制
56-
57- API Key 完全继承用户权限
58-
59- 如需限制权限,只需创建专门的 API 用户:
60-
61- 1 . 创建受限角色(如 ` API 只读角色 ` ),分配必要权限
62- 2 . 创建 API 用户,分配该角色
63- 3 . 使用该用户创建 API Key
Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ summary = 'API Key'
33version = ' 0.0.1'
44description = ' 用户自定义 API Key 管理,支持生成、管理和使用 API Key 进行接口认证'
55author = ' wu-clan'
6+ tags = [' auth' ]
7+ database = [' mysql' , ' pgsql' ]
68
79[app ]
810extend = ' admin'
You can’t perform that action at this time.
0 commit comments