Skip to content

Commit c4b0673

Browse files
committed
Remove duplicate auth class
1 parent 4f2a912 commit c4b0673

File tree

1 file changed

+0
-59
lines changed

1 file changed

+0
-59
lines changed

firebase_admin/messaging.py

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
import requests
2525
import httpx
2626

27-
from google.auth import credentials
28-
from google.auth.transport import requests as auth_requests
2927
from googleapiclient import http
3028
from googleapiclient import _auth
3129

@@ -435,63 +433,6 @@ def exception(self):
435433
"""A ``FirebaseError`` if an error occurs while sending the message to the FCM service."""
436434
return self._exception
437435

438-
# Auth Flow
439-
# TODO: Remove comments
440-
# The aim here is to be able to get auth credentials right before the request is sent.
441-
# This is similar to what is done in transport.requests.AuthorizedSession().
442-
# We can then pass this in at the client level.
443-
444-
# Notes:
445-
# - This implementations does not cover timeouts on requests sent to refresh credentials.
446-
# - Uses HTTP/1 and a blocking credential for refreshing.
447-
class GoogleAuthCredentialFlow(httpx.Auth):
448-
"""Google Auth Credential Auth Flow"""
449-
def __init__(self, credential: credentials.Credentials):
450-
self._credential = credential
451-
self._max_refresh_attempts = 2
452-
self._refresh_status_codes = (401,)
453-
454-
def apply_auth_headers(self, request: httpx.Request):
455-
# Build request used to refresh credentials if needed
456-
auth_request = auth_requests.Request()
457-
# This refreshes the credentials if needed and mutates the request headers to
458-
# contain access token and any other google auth headers
459-
self._credential.before_request(auth_request, request.method, request.url, request.headers)
460-
461-
462-
def auth_flow(self, request: httpx.Request):
463-
# Keep original headers since `credentials.before_request` mutates the passed headers and we
464-
# want to keep the original in cause we need an auth retry.
465-
_original_headers = request.headers.copy()
466-
467-
_credential_refresh_attempt = 0
468-
while _credential_refresh_attempt <= self._max_refresh_attempts:
469-
# copy original headers
470-
request.headers = _original_headers.copy()
471-
# mutates request headers
472-
logger.debug(
473-
'Refreshing credentials for request attempt %d',
474-
_credential_refresh_attempt + 1)
475-
self.apply_auth_headers(request)
476-
477-
# Continue to perform the request
478-
# yield here dispatches the request and returns with the response
479-
response: httpx.Response = yield request
480-
481-
# We can check the result of the response and determine in we need to retry
482-
# on refreshable status codes. Current transport.requests.AuthorizedSession()
483-
# only does this on 401 errors. We should do the same.
484-
if response.status_code in self._refresh_status_codes:
485-
logger.debug(
486-
'Request attempt %d failed due to unauthorized credentials',
487-
_credential_refresh_attempt + 1)
488-
_credential_refresh_attempt += 1
489-
else:
490-
break
491-
# Last yielded response is auto returned.
492-
493-
494-
495436
class _MessagingService:
496437
"""Service class that implements Firebase Cloud Messaging (FCM) functionality."""
497438

0 commit comments

Comments
 (0)