24
24
from firebase_admin import _user_identifier
25
25
from firebase_admin import _user_import
26
26
from firebase_admin import _user_mgt
27
-
27
+ from firebase_admin import _utils
28
28
29
29
class Client :
30
30
"""Firebase Authentication client scoped to a specific tenant."""
@@ -36,18 +36,37 @@ def __init__(self, app, tenant_id=None):
36
36
2. set the project ID explicitly via Firebase App options, or
37
37
3. set the project ID via the GOOGLE_CLOUD_PROJECT environment variable.""" )
38
38
39
- credential = app . credential . get_credential ()
39
+ credential = None
40
40
version_header = 'Python/Admin/{0}' .format (firebase_admin .__version__ )
41
41
timeout = app .options .get ('httpTimeout' , _http_client .DEFAULT_TIMEOUT_SECONDS )
42
+ # Non-default endpoint URLs for emulator support are set in this dict later.
43
+ endpoint_urls = {}
44
+ self .emulated = False
45
+
46
+ # If an emulator is present, check that the given value matches the expected format and set
47
+ # endpoint URLs to use the emulator. Additionally, use a fake credential.
48
+ emulator_host = _auth_utils .get_emulator_host ()
49
+ if emulator_host :
50
+ base_url = 'http://{0}/identitytoolkit.googleapis.com' .format (emulator_host )
51
+ endpoint_urls ['v1' ] = base_url + '/v1'
52
+ endpoint_urls ['v2beta1' ] = base_url + '/v2beta1'
53
+ credential = _utils .EmulatorAdminCredentials ()
54
+ self .emulated = True
55
+ else :
56
+ # Use credentials if provided
57
+ credential = app .credential .get_credential ()
58
+
42
59
http_client = _http_client .JsonHttpClient (
43
60
credential = credential , headers = {'X-Client-Version' : version_header }, timeout = timeout )
44
61
45
62
self ._tenant_id = tenant_id
46
- self ._token_generator = _token_gen .TokenGenerator (app , http_client )
63
+ self ._token_generator = _token_gen .TokenGenerator (
64
+ app , http_client , url_override = endpoint_urls .get ('v1' ))
47
65
self ._token_verifier = _token_gen .TokenVerifier (app )
48
- self ._user_manager = _user_mgt .UserManager (http_client , app .project_id , tenant_id )
66
+ self ._user_manager = _user_mgt .UserManager (
67
+ http_client , app .project_id , tenant_id , url_override = endpoint_urls .get ('v1' ))
49
68
self ._provider_manager = _auth_providers .ProviderConfigClient (
50
- http_client , app .project_id , tenant_id )
69
+ http_client , app .project_id , tenant_id , url_override = endpoint_urls . get ( 'v2beta1' ) )
51
70
52
71
@property
53
72
def tenant_id (self ):
@@ -108,7 +127,7 @@ def verify_id_token(self, id_token, check_revoked=False):
108
127
raise _auth_utils .TenantIdMismatchError (
109
128
'Invalid tenant ID: {0}' .format (token_tenant_id ))
110
129
111
- if check_revoked :
130
+ if not self . emulated and check_revoked :
112
131
self ._check_jwt_revoked (verified_claims , _token_gen .RevokedIdTokenError , 'ID token' )
113
132
return verified_claims
114
133
0 commit comments