rainycode 1.1.2__tar.gz → 1.1.3__tar.gz
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.
- {rainycode-1.1.2 → rainycode-1.1.3}/PKG-INFO +1 -1
- {rainycode-1.1.2 → rainycode-1.1.3}/common_servers/api/auth_api.py +2 -2
- {rainycode-1.1.2 → rainycode-1.1.3}/common_servers/service/auth_svc.py +8 -8
- {rainycode-1.1.2 → rainycode-1.1.3}/pyproject.toml +1 -1
- {rainycode-1.1.2 → rainycode-1.1.3}/rainycode.egg-info/PKG-INFO +1 -1
- {rainycode-1.1.2 → rainycode-1.1.3}/common_base/aiorequests.py +0 -0
- {rainycode-1.1.2 → rainycode-1.1.3}/common_base/consts.py +0 -0
- {rainycode-1.1.2 → rainycode-1.1.3}/common_base/exception.py +0 -0
- {rainycode-1.1.2 → rainycode-1.1.3}/common_base/logging.py +0 -0
- {rainycode-1.1.2 → rainycode-1.1.3}/common_base/response.py +0 -0
- {rainycode-1.1.2 → rainycode-1.1.3}/common_depends/auth_depend.py +0 -0
- {rainycode-1.1.2 → rainycode-1.1.3}/common_models/__init__.py +0 -0
- {rainycode-1.1.2 → rainycode-1.1.3}/common_models/base_model.py +0 -0
- {rainycode-1.1.2 → rainycode-1.1.3}/common_models/user_model.py +0 -0
- {rainycode-1.1.2 → rainycode-1.1.3}/common_models/wechat_model.py +0 -0
- {rainycode-1.1.2 → rainycode-1.1.3}/common_servers/api/wechat_api.py +0 -0
- {rainycode-1.1.2 → rainycode-1.1.3}/common_servers/router.py +0 -0
- {rainycode-1.1.2 → rainycode-1.1.3}/common_servers/schemas/__init__.py +0 -0
- {rainycode-1.1.2 → rainycode-1.1.3}/common_servers/schemas/auth_schema.py +0 -0
- {rainycode-1.1.2 → rainycode-1.1.3}/common_servers/service/wechat_svc.py +0 -0
- {rainycode-1.1.2 → rainycode-1.1.3}/common_utils/bcrypt_util.py +0 -0
- {rainycode-1.1.2 → rainycode-1.1.3}/common_utils/captcha_util.py +0 -0
- {rainycode-1.1.2 → rainycode-1.1.3}/common_utils/ip_util.py +0 -0
- {rainycode-1.1.2 → rainycode-1.1.3}/common_utils/jwt_util.py +0 -0
- {rainycode-1.1.2 → rainycode-1.1.3}/common_utils/snowflake_util.py +0 -0
- {rainycode-1.1.2 → rainycode-1.1.3}/common_utils/wechat_util.py +0 -0
- {rainycode-1.1.2 → rainycode-1.1.3}/core/base_config.py +0 -0
- {rainycode-1.1.2 → rainycode-1.1.3}/core/databases/aiodb.py +0 -0
- {rainycode-1.1.2 → rainycode-1.1.3}/core/databases/aioredis.py +0 -0
- {rainycode-1.1.2 → rainycode-1.1.3}/core/middleware/http_middleware.py +0 -0
- {rainycode-1.1.2 → rainycode-1.1.3}/core/start.py +0 -0
- {rainycode-1.1.2 → rainycode-1.1.3}/rainycode.egg-info/SOURCES.txt +0 -0
- {rainycode-1.1.2 → rainycode-1.1.3}/rainycode.egg-info/dependency_links.txt +0 -0
- {rainycode-1.1.2 → rainycode-1.1.3}/rainycode.egg-info/requires.txt +0 -0
- {rainycode-1.1.2 → rainycode-1.1.3}/rainycode.egg-info/top_level.txt +0 -0
- {rainycode-1.1.2 → rainycode-1.1.3}/setup.cfg +0 -0
|
@@ -58,7 +58,7 @@ async def login_mini(wechat_in: WechatLogin):
|
|
|
58
58
|
|
|
59
59
|
@router.get("/wechat/oauth", summary="获取微信网页授权链接 - 回调(/oauth/callback)")
|
|
60
60
|
async def get_wechat_oauth_url(
|
|
61
|
-
|
|
61
|
+
app_pk: int = Query(..., description="微信应用主键ID"),
|
|
62
62
|
redirect_uri: str = Query(..., description="授权成功后跳转地址"),
|
|
63
63
|
state: str | None = Query(default=None, description="自定义状态参数"),
|
|
64
64
|
):
|
|
@@ -69,5 +69,5 @@ async def get_wechat_oauth_url(
|
|
|
69
69
|
- 如果用户已注册,回调后直接返回 token
|
|
70
70
|
- 如果用户未注册,自动重定向到 snsapi_userinfo 授权
|
|
71
71
|
"""
|
|
72
|
-
authorize_url = await AuthService.get_wechat_oauth_url(
|
|
72
|
+
authorize_url = await AuthService.get_wechat_oauth_url(app_pk, redirect_uri, state)
|
|
73
73
|
return SuccessReturn(data={"authorize_url": authorize_url})
|
|
@@ -146,17 +146,17 @@ class AuthService:
|
|
|
146
146
|
logger.info(f"用户登出: user_id={user_id}, username={username}")
|
|
147
147
|
|
|
148
148
|
@classmethod
|
|
149
|
-
async def get_wechat_oauth_url(cls,
|
|
149
|
+
async def get_wechat_oauth_url(cls, app_pk: int, redirect_uri: str, state: str | None = None) -> str:
|
|
150
150
|
"""
|
|
151
151
|
生成微信网页授权链接(snsapi_base)
|
|
152
152
|
|
|
153
|
-
:param
|
|
153
|
+
:param app_pk: 微信应用主键ID
|
|
154
154
|
:param redirect_uri: 授权成功后跳转的前端地址
|
|
155
155
|
:param state: 自定义状态参数
|
|
156
156
|
:return: 微信授权链接
|
|
157
157
|
"""
|
|
158
158
|
# 验证公众号配置
|
|
159
|
-
app_config = await WechatApp.get_or_none(
|
|
159
|
+
app_config = await WechatApp.get_or_none(id=app_pk, app_type=AppTypeEnum.OFFICIAL_ACCOUNT)
|
|
160
160
|
if not app_config:
|
|
161
161
|
raise CustomException(msg="无效的公众号配置")
|
|
162
162
|
|
|
@@ -168,8 +168,8 @@ class AuthService:
|
|
|
168
168
|
# 生成内部 state
|
|
169
169
|
internal_state = state or str(uuid.uuid4())
|
|
170
170
|
|
|
171
|
-
# 缓存 state -> (redirect_uri,
|
|
172
|
-
cache_value = json.dumps({"redirect_uri": redirect_uri, "
|
|
171
|
+
# 缓存 state -> (redirect_uri, app_pk) 映射,有效期 5 分钟
|
|
172
|
+
cache_value = json.dumps({"redirect_uri": redirect_uri, "app_pk": app_pk})
|
|
173
173
|
await AioRedis.set(f"{REDIS_PREFIX_OAUTH_STATE}{internal_state}", cache_value, ex=300)
|
|
174
174
|
|
|
175
175
|
# 构建回调地址
|
|
@@ -202,11 +202,11 @@ class AuthService:
|
|
|
202
202
|
try:
|
|
203
203
|
cached_data = json.loads(cache_value)
|
|
204
204
|
redirect_uri = cached_data.get("redirect_uri")
|
|
205
|
-
|
|
205
|
+
app_pk = cached_data.get("app_pk")
|
|
206
206
|
except (json.JSONDecodeError, TypeError):
|
|
207
207
|
raise CustomException(msg="授权数据格式错误")
|
|
208
208
|
|
|
209
|
-
if not redirect_uri or not
|
|
209
|
+
if not redirect_uri or not app_pk:
|
|
210
210
|
raise CustomException(msg="授权数据不完整")
|
|
211
211
|
|
|
212
212
|
# 删除已使用的 state
|
|
@@ -218,7 +218,7 @@ class AuthService:
|
|
|
218
218
|
raise CustomException(msg="授权码已失效,请重新授权")
|
|
219
219
|
|
|
220
220
|
# 获取公众号配置
|
|
221
|
-
app_config = await WechatApp.get_or_none(
|
|
221
|
+
app_config = await WechatApp.get_or_none(id=app_pk, app_type=AppTypeEnum.OFFICIAL_ACCOUNT)
|
|
222
222
|
if not app_config:
|
|
223
223
|
raise CustomException(msg="公众号配置不存在")
|
|
224
224
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|