What I'm trying to do is connect an emulator to an instance of firebase_admin for admin authentication and another instance for web authentication in the same api.
The problem is that i cannot set the host of each emulator for each instance of firebase_admin. What happens is that it always takes the environment variable that it declares in the last instance of the module. As can be seen in the following python script.
#!/usr/bin/env python3
"""
src.firebase.py
Initialize firebase_admin for admin & web
"""
import os
from firebase_admin import initialize_app
from firebase_admin import credentials
from firebase_admin import auth
def initialize_admin():
os.environ["FIREBASE_AUTH_EMULATOR_HOST"] = os.getenv("FIREBASE_AUTH_EMULATOR_ADMIN_HOST")
sdk_cred = credentials.Certificate(
os.path.abspath(
os.path.join(__package__, "./config/conexperto-admin-sdk.json")
)
)
return initialize_app(
credential=sdk_cred, name="admin"
)
def initialize_web():
os.environ["FIREBASE_AUTH_EMULATOR_HOST"] = os.getenv("FIREBASE_AUTH_EMULATOR_WEB_HOST")
sdk_cred = credentials.Certificate(
os.path.abspath(
os.path.join(__package__, "./config/conexperto-web-sdk.json")
)
)
return initialize_app(
credential=sdk_cred, name="web"
)
admin_sdk = initialize_admin()
web_sdk = initialize_web()
user_admin = auth.get_user(uid, app=admin_sdk) # in this instance admin_sdk is linked to the emulator web, what causes the error
web_admin = auth.get_user(uid, app=web_sdk)
Therefore, when creating an admin user, it is signed with the credentials of admin_sdk and saved in the web emulator. That when logging in with said user and verifying the token, it will throw a signature error 'aud'.
firebase_admin version that I am using
firebase_admin-5.0.1