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,17 +36,36 @@ 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
+ # Non-default endpoint URLs for emulator support are set in this dict later.
42
+ endpoint_urls = {}
43
+ self .emulated = False
44
+
45
+ # If an emulator is present, check that the given value matches the expected format and set
46
+ # endpoint URLs to use the emulator. Additionally, use a fake credential.
47
+ emulator_host = _auth_utils .get_emulator_host ()
48
+ if emulator_host :
49
+ base_url = 'http://{0}/identitytoolkit.googleapis.com' .format (emulator_host )
50
+ endpoint_urls ['v1' ] = base_url + '/v1'
51
+ endpoint_urls ['v2beta1' ] = base_url + '/v2beta1'
52
+ credential = _utils .EmulatorAdminCredentials ()
53
+ self .emulated = True
54
+ else :
55
+ # Use credentials if provided
56
+ credential = app .credential .get_credential ()
57
+
41
58
http_client = _http_client .JsonHttpClient (
42
59
credential = credential , headers = {'X-Client-Version' : version_header })
43
60
44
61
self ._tenant_id = tenant_id
45
- self ._token_generator = _token_gen .TokenGenerator (app , http_client )
62
+ self ._token_generator = _token_gen .TokenGenerator (
63
+ app , http_client , url_override = endpoint_urls .get ('v1' ))
46
64
self ._token_verifier = _token_gen .TokenVerifier (app )
47
- self ._user_manager = _user_mgt .UserManager (http_client , app .project_id , tenant_id )
65
+ self ._user_manager = _user_mgt .UserManager (
66
+ http_client , app .project_id , tenant_id , url_override = endpoint_urls .get ('v1' ))
48
67
self ._provider_manager = _auth_providers .ProviderConfigClient (
49
- http_client , app .project_id , tenant_id )
68
+ http_client , app .project_id , tenant_id , url_override = endpoint_urls . get ( 'v2beta1' ) )
50
69
51
70
@property
52
71
def tenant_id (self ):
@@ -107,7 +126,7 @@ def verify_id_token(self, id_token, check_revoked=False):
107
126
raise _auth_utils .TenantIdMismatchError (
108
127
'Invalid tenant ID: {0}' .format (token_tenant_id ))
109
128
110
- if check_revoked :
129
+ if not self . emulated and check_revoked :
111
130
self ._check_jwt_revoked (verified_claims , _token_gen .RevokedIdTokenError , 'ID token' )
112
131
return verified_claims
113
132
0 commit comments