2020from jwt import InvalidAudienceError , InvalidIssuerError , InvalidSignatureError
2121from firebase_admin import _utils
2222from firebase_admin import _http_client
23+ import requests
2324
2425_APP_CHECK_ATTRIBUTE = '_app_check'
2526
@@ -49,6 +50,7 @@ class _AppCheckService:
4950
5051 _APP_CHECK_ISSUER = 'https://firebaseappcheck.googleapis.com/'
5152 _JWKS_URL = 'https://firebaseappcheck.googleapis.com/v1/jwks'
53+ _APP_CHECK_V1BETA_URL = 'https://firebaseappcheck.googleapis.com/v1beta'
5254 _project_id = None
5355 _scoped_project_id = None
5456 _jwks_client = None
@@ -73,7 +75,7 @@ def __init__(self, app):
7375 self ._JWKS_URL , lifespan = 21600 , headers = self ._APP_CHECK_HEADERS )
7476 self ._http_client = _http_client .JsonHttpClient (
7577 credential = app .credential ,
76- base_url = 'https://firebaseappcheck.googleapis.com/v1beta' )
78+ base_url = self . _APP_CHECK_V1BETA_URL )
7779
7880
7981 def verify_token (self , token : str , consume : bool = False ) -> Dict [str , Any ]:
@@ -100,10 +102,13 @@ def verify_token(self, token: str, consume: bool = False) -> Dict[str, Any]:
100102
101103 def _verify_replay_protection (self , token : str ) -> bool :
102104 """Verifies the token's consumption status."""
103- path = f'/ { self ._scoped_project_id } :verifyAppCheckToken'
105+ path = f'{ self ._scoped_project_id } :verifyAppCheckToken'
104106 body = {'app_check_token' : token }
105- response = self ._http_client .body ('post' , path , json = body )
106- return response .get ('alreadyConsumed' , False )
107+ try :
108+ response = self ._http_client .body ('post' , path , json = body )
109+ return response .get ('alreadyConsumed' , False )
110+ except requests .exceptions .RequestException as error :
111+ raise _utils .handle_platform_error_from_requests (error )
107112
108113 def _has_valid_token_headers (self , headers : Any ) -> None :
109114 """Checks whether the token has valid headers for App Check."""
0 commit comments