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