mirror of
https://github.com/lanqian528/chat2api.git
synced 2026-06-13 21:02:46 +08:00
This commit is contained in:
parent
997ea02a3a
commit
a0d539ccdd
@ -105,6 +105,9 @@ async def verify_token(req_token):
|
||||
return access_token
|
||||
elif len(req_token) == 45:
|
||||
try:
|
||||
if req_token in globals.error_token_list:
|
||||
raise HTTPException(status_code=401, detail="Error RefreshToken")
|
||||
|
||||
access_token = await rt2ac(req_token, force_refresh=False)
|
||||
return access_token
|
||||
except HTTPException as e:
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
import threading
|
||||
import time
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
import json
|
||||
import random
|
||||
import time
|
||||
|
||||
import jwt
|
||||
from fastapi import Request, HTTPException, Security
|
||||
from fastapi.responses import Response
|
||||
from fastapi.security import HTTPAuthorizationCredentials
|
||||
@ -219,14 +221,17 @@ async def refresh(request: Request):
|
||||
if not refresh_token and not access_token:
|
||||
raise HTTPException(status_code=401, detail="refresh_token or access_token is required")
|
||||
|
||||
need_refresh = True
|
||||
if access_token:
|
||||
account_check_info = await chatgpt_account_check(access_token)
|
||||
if account_check_info:
|
||||
auth_info.update(account_check_info)
|
||||
auth_info.update({"accessToken": access_token})
|
||||
return Response(content=json.dumps(auth_info), media_type="application/json")
|
||||
try:
|
||||
access_token_info = jwt.decode(access_token, options={"verify_signature": False})
|
||||
exp = access_token_info.get("exp", 0)
|
||||
if exp > int(time.time()) + 60 * 60 * 24 * 5:
|
||||
need_refresh = False
|
||||
except Exception as e:
|
||||
logger.error(f"access_token: {e}")
|
||||
|
||||
if refresh_token:
|
||||
if refresh_token and need_refresh:
|
||||
chatgpt_refresh_info = await chatgpt_refresh(refresh_token)
|
||||
if chatgpt_refresh_info:
|
||||
auth_info.update(chatgpt_refresh_info)
|
||||
@ -236,4 +241,13 @@ async def refresh(request: Request):
|
||||
auth_info.update(account_check_info)
|
||||
auth_info.update({"accessToken": access_token})
|
||||
return Response(content=json.dumps(auth_info), media_type="application/json")
|
||||
elif access_token:
|
||||
account_check_info = await chatgpt_account_check(access_token)
|
||||
if account_check_info:
|
||||
auth_info.update(account_check_info)
|
||||
auth_info.update({"accessToken": access_token})
|
||||
return Response(content=json.dumps(auth_info), media_type="application/json")
|
||||
|
||||
raise HTTPException(status_code=401, detail="Unauthorized")
|
||||
|
||||
|
||||
|
||||
@ -10,3 +10,4 @@ pybase64
|
||||
jinja2
|
||||
APScheduler
|
||||
ua-generator
|
||||
pyjwt
|
||||
@ -1 +1 @@
|
||||
1.7.0-beta2
|
||||
1.7.0-beta3
|
||||
Loading…
Reference in New Issue
Block a user