From 4a4cee52d3d4fe584fe1c8940a1814ec404942e4 Mon Sep 17 00:00:00 2001 From: Rendy Arya Kemal Date: Sun, 2 Jun 2024 13:54:31 +0700 Subject: [PATCH] feat: add emulator script to create custom token --- get_emulator_token.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 get_emulator_token.py diff --git a/get_emulator_token.py b/get_emulator_token.py new file mode 100644 index 0000000..e031fed --- /dev/null +++ b/get_emulator_token.py @@ -0,0 +1,21 @@ +import os +from typing import cast +from firebase_admin import auth +import httpx +from cefies.internal.firestore import app + +API_KEY = os.getenv("API_KEY", "") + +try: + user = auth.get_user_by_email(email="example@example.com") +except: + user: auth.UserRecord = auth.create_user(email="example@example.com", password="sample") + +custom_token = auth.create_custom_token(user.uid).decode() +response = httpx.post( + "http://localhost:9099/www.googleapis.com/identitytoolkit/v3/relyingparty/verifyCustomToken?key=" + API_KEY, + json={"token": custom_token, "returnSecureToken": True}, +) + + +print(response.json())