次の記事を参考にしました。
PythonでFirebase Authenticationのトークン取得とFastAPIでトークン検証
参考ページ
Relyingparty: verifyPassword
get_token.py
#! /usr/bin/python
# -*- coding: utf-8 -*-
#
# get_token.py
#
# Feb/06/2021
#
# ----------------------------------------------------------------
import sys
import os
import requests
from dotenv import load_dotenv
# ----------------------------------------------------------------
sys.stderr.write("*** 開始 ***\n")
email = sys.argv[1]
password = sys.argv[2]
sys.stderr.write("email = " + email + "\n")
sys.stderr.write("password = " + password + "\n")
dotenv_path = '.env'
load_dotenv(dotenv_path)
api_key = os.environ.get("API_KEY")
uri = f"https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyPassword?key={api_key}"
data = {"email": email, "password": password, "returnSecureToken": True}
result = requests.post(url=uri, data=data).json()
token = result['idToken']
print(token)
sys.stderr.write("*** 終了 ***\n")
# ----------------------------------------------------------------
.env
API_KEY = "AIzaS....."
実行スクリプト
./get_token.py ppp@example.com hello888 > token01.txt
./get_token.py qqq@example.com hello999 > token02.txt