skyplatform-iam 1.0.3__py3-none-any.whl → 1.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- skyplatform_iam/__init__.py +57 -2
- skyplatform_iam/connect_agenterra_iam.py +232 -62
- skyplatform_iam-1.1.0.dist-info/METADATA +461 -0
- skyplatform_iam-1.1.0.dist-info/RECORD +8 -0
- skyplatform_iam-1.0.3.dist-info/METADATA +0 -261
- skyplatform_iam-1.0.3.dist-info/RECORD +0 -8
- {skyplatform_iam-1.0.3.dist-info → skyplatform_iam-1.1.0.dist-info}/WHEEL +0 -0
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: skyplatform-iam
|
|
3
|
-
Version: 1.0.3
|
|
4
|
-
Summary: SkyPlatform IAM认证SDK,提供FastAPI中间件和认证路由
|
|
5
|
-
Project-URL: Homepage, https://github.com/xinmayoujiang12621/agenterra_iam
|
|
6
|
-
Project-URL: Documentation, https://skyplatform-iam.readthedocs.io/
|
|
7
|
-
Project-URL: Repository, https://github.com/xinmayoujiang12621/agenterra_iam.git
|
|
8
|
-
Project-URL: Issues, https://github.com/xinmayoujiang12621/agenterra_iam/issues
|
|
9
|
-
Project-URL: Changelog, https://github.com/xinmayoujiang12621/agenterra_iam/blob/main/CHANGELOG.md
|
|
10
|
-
Author-email: x9 <xuanxienanxunmobao@gmail.com>
|
|
11
|
-
License: MIT
|
|
12
|
-
Keywords: authentication,fastapi,iam,middleware,skyplatform
|
|
13
|
-
Classifier: Development Status :: 5 - Production/Stable
|
|
14
|
-
Classifier: Framework :: FastAPI
|
|
15
|
-
Classifier: Intended Audience :: Developers
|
|
16
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
-
Classifier: Operating System :: OS Independent
|
|
18
|
-
Classifier: Programming Language :: Python :: 3
|
|
19
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
20
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
21
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
22
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
23
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
24
|
-
Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
|
|
25
|
-
Classifier: Topic :: Security
|
|
26
|
-
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
27
|
-
Requires-Python: >=3.9
|
|
28
|
-
Requires-Dist: fastapi>=0.68.0
|
|
29
|
-
Requires-Dist: pydantic>=1.8.0
|
|
30
|
-
Requires-Dist: requests>=2.25.0
|
|
31
|
-
Requires-Dist: starlette>=0.14.0
|
|
32
|
-
Provides-Extra: dev
|
|
33
|
-
Requires-Dist: black>=22.0.0; extra == 'dev'
|
|
34
|
-
Requires-Dist: flake8>=4.0.0; extra == 'dev'
|
|
35
|
-
Requires-Dist: httpx>=0.23.0; extra == 'dev'
|
|
36
|
-
Requires-Dist: isort>=5.10.0; extra == 'dev'
|
|
37
|
-
Requires-Dist: mypy>=0.950; extra == 'dev'
|
|
38
|
-
Requires-Dist: pytest-asyncio>=0.18.0; extra == 'dev'
|
|
39
|
-
Requires-Dist: pytest>=6.0.0; extra == 'dev'
|
|
40
|
-
Description-Content-Type: text/markdown
|
|
41
|
-
|
|
42
|
-
# SkyPlatform IAM SDK
|
|
43
|
-
|
|
44
|
-
SkyPlatform IAM认证SDK,提供FastAPI中间件和认证路由,简化第三方服务的认证集成。
|
|
45
|
-
|
|
46
|
-
## 功能特性
|
|
47
|
-
|
|
48
|
-
- 🔐 **FastAPI中间件**: 自动拦截请求进行Token验证和权限检查
|
|
49
|
-
- 🚀 **认证路由**: 封装用户注册、登录、登出等认证接口
|
|
50
|
-
- ⚙️ **灵活配置**: 支持环境变量和代码配置
|
|
51
|
-
- 🛡️ **白名单机制**: 支持配置无需认证的路径
|
|
52
|
-
- 🔧 **完整兼容**: 基于现有ConnectAgenterraIam类,保持完全兼容
|
|
53
|
-
- 📝 **类型提示**: 完整的TypeScript风格类型提示
|
|
54
|
-
- 🚨 **异常处理**: 完善的错误处理和自定义异常
|
|
55
|
-
|
|
56
|
-
## 快速开始
|
|
57
|
-
|
|
58
|
-
### 安装
|
|
59
|
-
|
|
60
|
-
```bash
|
|
61
|
-
pip install skyplatform-iam
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
### 环境变量配置
|
|
65
|
-
|
|
66
|
-
创建 `.env` 文件或设置环境变量:
|
|
67
|
-
|
|
68
|
-
```bash
|
|
69
|
-
AGENTERRA_IAM_HOST=https://your-iam-host.com
|
|
70
|
-
AGENTERRA_SERVER_NAME=your-server-name
|
|
71
|
-
AGENTERRA_ACCESS_KEY=your-access-key
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
### 基本使用
|
|
75
|
-
|
|
76
|
-
#### 方式1:一键设置(推荐)
|
|
77
|
-
|
|
78
|
-
```python
|
|
79
|
-
from fastapi import FastAPI
|
|
80
|
-
from skyplatform_iam import setup_auth
|
|
81
|
-
|
|
82
|
-
app = FastAPI()
|
|
83
|
-
|
|
84
|
-
# 一键设置认证中间件和路由
|
|
85
|
-
setup_auth(app)
|
|
86
|
-
|
|
87
|
-
@app.get("/protected")
|
|
88
|
-
async def protected_endpoint(request):
|
|
89
|
-
# 获取用户信息(由中间件自动设置)
|
|
90
|
-
user = request.state.user
|
|
91
|
-
return {"message": "访问成功", "user": user}
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
#### 方式2:手动设置
|
|
95
|
-
|
|
96
|
-
```python
|
|
97
|
-
from fastapi import FastAPI
|
|
98
|
-
from skyplatform_iam import AuthConfig, AuthMiddleware, create_auth_router
|
|
99
|
-
|
|
100
|
-
app = FastAPI()
|
|
101
|
-
|
|
102
|
-
# 创建配置
|
|
103
|
-
config = AuthConfig.from_env()
|
|
104
|
-
|
|
105
|
-
# 添加认证中间件
|
|
106
|
-
app.add_middleware(AuthMiddleware, config=config)
|
|
107
|
-
|
|
108
|
-
# 添加认证路由
|
|
109
|
-
auth_router = create_auth_router(config=config, prefix="/auth")
|
|
110
|
-
app.include_router(auth_router)
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
#### 方式3:自定义配置
|
|
114
|
-
|
|
115
|
-
```python
|
|
116
|
-
from skyplatform_iam import AuthConfig, setup_auth
|
|
117
|
-
|
|
118
|
-
# 自定义配置
|
|
119
|
-
config = AuthConfig(
|
|
120
|
-
agenterra_iam_host="https://your-iam-host.com",
|
|
121
|
-
server_name="your-server-name",
|
|
122
|
-
access_key="your-access-key",
|
|
123
|
-
whitelist_paths=[
|
|
124
|
-
"/docs", "/redoc", "/openapi.json",
|
|
125
|
-
"/health", "/public",
|
|
126
|
-
"/auth/register", "/auth/login"
|
|
127
|
-
],
|
|
128
|
-
enable_debug=True
|
|
129
|
-
)
|
|
130
|
-
|
|
131
|
-
setup_auth(app, config=config)
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
## API接口
|
|
135
|
-
|
|
136
|
-
SDK自动提供以下认证接口:
|
|
137
|
-
|
|
138
|
-
- `POST /auth/register` - 用户注册
|
|
139
|
-
- `POST /auth/login` - 用户登录
|
|
140
|
-
- `POST /auth/login_without_password` - 免密登录
|
|
141
|
-
- `POST /auth/logout` - 用户登出
|
|
142
|
-
- `POST /auth/reset_password` - 重置密码
|
|
143
|
-
- `POST /auth/refresh_token` - 刷新Token
|
|
144
|
-
- `POST /auth/assign_role` - 分配角色
|
|
145
|
-
- `POST /auth/user_info` - 获取用户信息
|
|
146
|
-
|
|
147
|
-
## 中间件功能
|
|
148
|
-
|
|
149
|
-
### 自动Token验证
|
|
150
|
-
|
|
151
|
-
中间件会自动:
|
|
152
|
-
1. 检查请求路径是否在白名单中
|
|
153
|
-
2. 从请求头提取Authorization Token
|
|
154
|
-
3. 调用IAM服务验证Token和权限
|
|
155
|
-
4. 将用户信息设置到 `request.state.user`
|
|
156
|
-
|
|
157
|
-
### 白名单配置
|
|
158
|
-
|
|
159
|
-
默认白名单路径:
|
|
160
|
-
- `/docs`, `/redoc`, `/openapi.json` - API文档
|
|
161
|
-
- `/health` - 健康检查
|
|
162
|
-
- `/auth/*` - 认证相关接口
|
|
163
|
-
|
|
164
|
-
添加自定义白名单:
|
|
165
|
-
|
|
166
|
-
```python
|
|
167
|
-
config = AuthConfig.from_env()
|
|
168
|
-
config.add_whitelist_path("/public")
|
|
169
|
-
config.add_whitelist_path("/status")
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
### 获取用户信息
|
|
173
|
-
|
|
174
|
-
在受保护的路由中获取用户信息:
|
|
175
|
-
|
|
176
|
-
```python
|
|
177
|
-
@app.get("/user-profile")
|
|
178
|
-
async def get_user_profile(request):
|
|
179
|
-
if hasattr(request.state, 'user'):
|
|
180
|
-
user = request.state.user
|
|
181
|
-
return {
|
|
182
|
-
"user_id": user["user_id"],
|
|
183
|
-
"username": user["username"],
|
|
184
|
-
"session_id": user["session_id"]
|
|
185
|
-
}
|
|
186
|
-
else:
|
|
187
|
-
raise HTTPException(status_code=401, detail="未认证")
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
## 异常处理
|
|
191
|
-
|
|
192
|
-
SDK提供完整的异常处理:
|
|
193
|
-
|
|
194
|
-
```python
|
|
195
|
-
from skyplatform_iam.exceptions import (
|
|
196
|
-
AuthenticationError, # 认证失败
|
|
197
|
-
AuthorizationError, # 权限不足
|
|
198
|
-
TokenExpiredError, # Token过期
|
|
199
|
-
TokenInvalidError, # Token无效
|
|
200
|
-
ConfigurationError, # 配置错误
|
|
201
|
-
IAMServiceError, # IAM服务错误
|
|
202
|
-
NetworkError # 网络错误
|
|
203
|
-
)
|
|
204
|
-
```
|
|
205
|
-
|
|
206
|
-
## 配置选项
|
|
207
|
-
|
|
208
|
-
### AuthConfig参数
|
|
209
|
-
|
|
210
|
-
| 参数 | 类型 | 必填 | 说明 |
|
|
211
|
-
|------|------|------|------|
|
|
212
|
-
| `agenterra_iam_host` | str | ✓ | IAM服务地址 |
|
|
213
|
-
| `server_name` | str | ✓ | 服务名称 |
|
|
214
|
-
| `access_key` | str | ✓ | 访问密钥 |
|
|
215
|
-
| `whitelist_paths` | List[str] | ✗ | 白名单路径 |
|
|
216
|
-
| `token_header` | str | ✗ | Token请求头名称(默认:Authorization) |
|
|
217
|
-
| `token_prefix` | str | ✗ | Token前缀(默认:Bearer ) |
|
|
218
|
-
| `enable_debug` | bool | ✗ | 启用调试模式 |
|
|
219
|
-
|
|
220
|
-
## 开发和测试
|
|
221
|
-
|
|
222
|
-
### 运行测试
|
|
223
|
-
|
|
224
|
-
```bash
|
|
225
|
-
# 安装开发依赖
|
|
226
|
-
pip install -e ".[dev]"
|
|
227
|
-
|
|
228
|
-
# 运行测试
|
|
229
|
-
python examples/test_sdk.py
|
|
230
|
-
```
|
|
231
|
-
|
|
232
|
-
### 运行示例
|
|
233
|
-
|
|
234
|
-
```bash
|
|
235
|
-
# 启动示例应用
|
|
236
|
-
python examples/basic_usage.py
|
|
237
|
-
|
|
238
|
-
# 访问 http://localhost:8000/docs 查看API文档
|
|
239
|
-
```
|
|
240
|
-
|
|
241
|
-
## 兼容性
|
|
242
|
-
|
|
243
|
-
- Python 3.8+
|
|
244
|
-
- FastAPI 0.68.0+
|
|
245
|
-
- 完全兼容现有的 `ConnectAgenterraIam` 类
|
|
246
|
-
|
|
247
|
-
## 许可证
|
|
248
|
-
|
|
249
|
-
MIT License
|
|
250
|
-
|
|
251
|
-
## 贡献
|
|
252
|
-
|
|
253
|
-
欢迎提交Issue和Pull Request!
|
|
254
|
-
|
|
255
|
-
## 更新日志
|
|
256
|
-
|
|
257
|
-
### v1.0.0
|
|
258
|
-
- 初始版本发布
|
|
259
|
-
- 提供FastAPI中间件和认证路由
|
|
260
|
-
- 支持完整的认证功能
|
|
261
|
-
- 兼容现有ConnectAgenterraIam类
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
skyplatform_iam/__init__.py,sha256=3I9OSLQS8-5CLwWobi2Zxuw1yw1Fro3ez9gd-HSGL_s,2835
|
|
2
|
-
skyplatform_iam/config.py,sha256=s4tctVpguKZv4O1Fhf7_Fo7zELNX6KYviMjkE1WPbQM,3715
|
|
3
|
-
skyplatform_iam/connect_agenterra_iam.py,sha256=uC4SoKRPHOaY_99o8TYfUDXHOvsFqxPiVAb5NYax0D0,34540
|
|
4
|
-
skyplatform_iam/exceptions.py,sha256=Rt55QIzVK1F_kn6yzKQKKakD6PZDFdPLCGaCphKKms8,2166
|
|
5
|
-
skyplatform_iam/middleware.py,sha256=XNJxvjw3O55TW-ff_uORK-C9Wy4BTAfkcnNjy1SQkx0,15721
|
|
6
|
-
skyplatform_iam-1.0.3.dist-info/METADATA,sha256=y2Lby7o6Z2meqorX5s0PpxOfdlfWIc-gyQZ8YVWwgXw,6990
|
|
7
|
-
skyplatform_iam-1.0.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
8
|
-
skyplatform_iam-1.0.3.dist-info/RECORD,,
|
|
File without changes
|