ooqd-project / refresh_token_test.py
kevin
fix
bb0c03b
import json
import os
import httpx
import asyncio
from utils import settings
FIREBASE_API_KEY = settings.FIREBASE_API_KEY
async def sign_in_with_idp():
url = "https://identitytoolkit.googleapis.com/v1/accounts:signInWithIdp"
# 查询参数
params = {
"key": FIREBASE_API_KEY
}
# 请求头
headers = {
"X-Client-Version": "Node/JsCore/10.5.2/FirebaseCore-web",
"X-Firebase-gmpid": "1:252179682924:web:9c80c6a32cb4682cbfaa49",
"Content-Type": "application/json",
"User-Agent": "node-fetch/1.0 (+https://github.com/bitinn/node-fetch)"
}
# 请求体
data = {
"requestUri": "http://localhost",
"returnSecureToken": True,
"postBody": f"&id_token={os.getenv('AUTHORIZATION_TOKEN', '')}&providerId=google.com"
}
print("Request Headers:", json.dumps(headers, indent=2)) # 格式化打印
print("Request Body:", json.dumps(data, indent=2)) # 格式化打印
print("Request params:", json.dumps(params, indent=2)) # 格式化打印
async with httpx.AsyncClient() as client:
response = await client.post(
url,
params=params,
headers=headers,
json=data
)
return response.json()
async def main():
result = await sign_in_with_idp()
print(result)
if __name__ == "__main__":
asyncio.run(main())