Skip to content

Commit 4279d45

Browse files
committed
Update the plugin config
1 parent 51b0ae5 commit 4279d45

2 files changed

Lines changed: 9 additions & 29 deletions

File tree

README.md

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
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+
# 基础配置
1314
API_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

plugin.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ summary = 'API Key'
33
version = '0.0.1'
44
description = '用户自定义 API Key 管理,支持生成、管理和使用 API Key 进行接口认证'
55
author = 'wu-clan'
6+
tags = ['auth']
7+
database = ['mysql', 'pgsql']
68

79
[app]
810
extend = 'admin'

0 commit comments

Comments
 (0)