File size: 1,394 Bytes
070ddfe
 
 
960721d
 
 
 
 
0b1c11c
960721d
 
 
 
 
0b1c11c
960721d
 
 
 
 
 
 
 
 
 
 
 
 
 
c4d9e3b
960721d
070ddfe
 
bb0c03b
960721d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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())