Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
8727e91
feat(firestore): Add Firestore Multi Database Support (#818)
jonathanedey Oct 24, 2024
2a8170f
[chore] Bump cachecontrol (#819)
jonathanedey Oct 24, 2024
d8d6aea
chore: Create dependabot.yml (#820)
lahirumaramba Oct 24, 2024
32e8dd2
feat: Support passing `google.auth` typed credentials in `initialize_…
jonathanedey Nov 4, 2024
be56a0f
chore: Add `X-Goog-Api-Client` metric header to requests (#826)
jonathanedey Nov 4, 2024
50ace23
feat(firestore): Upgrade `google-cloud-firestore` to support Firestor…
jonathanedey Nov 7, 2024
d3e2a63
[chore] Release 6.6.0 (#829)
jonathanedey Nov 7, 2024
1b131f0
[chore] Release 6.6.0 Take 2 (#830)
jonathanedey Nov 7, 2024
e377491
Adding script for Python Bug Bash
Dec 4, 2024
f9f0635
Changes for percent comparison
Dec 5, 2024
5f6f03e
Fixing semantic version issues with invalid version
Dec 8, 2024
ba678a9
Config values must retrun default values from invalid get operations
Dec 8, 2024
84ebe4c
Fixing typos
Dec 18, 2024
12fb2f1
Adding requirements set is master branch
Dec 18, 2024
d276c3e
Updating tolerance for percentage evaluation
Dec 18, 2024
f22ef5b
Removing dependency changes from fix branch
Dec 18, 2024
43ab91e
chore: Skip integration test for deprecated FCM API and bump pypy CI …
jonathanedey Dec 19, 2024
8ba819a
chore: Adding delayed response message for holidays (#842)
jonathanedey Dec 20, 2024
00dff8c
Updating ServerConfig methods
Jan 5, 2025
a08b91b
Updating ServerConfig methods
Jan 5, 2025
0ce187f
Revert "chore: Adding delayed response message for holidays (#842)" (…
jonathanedey Jan 6, 2025
0788d22
Updating comments and vars for readability
Jan 7, 2025
2faf53f
feat(firestore): Add Firestore Multi Database Support (#818)
jonathanedey Oct 24, 2024
7ff94da
[chore] Bump cachecontrol (#819)
jonathanedey Oct 24, 2024
f0c504b
chore: Create dependabot.yml (#820)
lahirumaramba Oct 24, 2024
464f442
feat: Support passing `google.auth` typed credentials in `initialize_…
jonathanedey Nov 4, 2024
746ea96
chore: Add `X-Goog-Api-Client` metric header to requests (#826)
jonathanedey Nov 4, 2024
75d1746
feat(firestore): Upgrade `google-cloud-firestore` to support Firestor…
jonathanedey Nov 7, 2024
80f6fe3
[chore] Release 6.6.0 (#829)
jonathanedey Nov 7, 2024
6d8223c
[chore] Release 6.6.0 Take 2 (#830)
jonathanedey Nov 7, 2024
45c9ad6
chore: Skip integration test for deprecated FCM API and bump pypy CI …
jonathanedey Dec 19, 2024
61833d5
chore: Adding delayed response message for holidays (#842)
jonathanedey Dec 20, 2024
6088f28
Revert "chore: Adding delayed response message for holidays (#842)" (…
jonathanedey Jan 6, 2025
e940950
Implementation for Fetching and Caching Server Side Remote Config (#825)
pijushcs Nov 15, 2024
ccb186a
Implementation for Evaluating Condition and Custom Signals Server Sid…
rathovarun1032 Nov 15, 2024
473d31f
Adding script for Python Bug Bash
Dec 4, 2024
7264d31
Changes for percent comparison
Dec 5, 2024
43a6862
Fixing semantic version issues with invalid version
Dec 8, 2024
0f50a95
Config values must retrun default values from invalid get operations
Dec 8, 2024
4bae22c
Fixing typos
Dec 18, 2024
797611b
Updating tolerance for percentage evaluation
Dec 18, 2024
55990cf
Removing dependency changes from fix branch
Dec 18, 2024
b4b4c1f
Updating ServerConfig methods
Jan 5, 2025
ced6140
Updating ServerConfig methods
Jan 5, 2025
40d0672
Updating comments and vars for readability
Jan 7, 2025
19a8156
Merge branch 'ssrc-bug-bash' of github.com:firebase/firebase-admin-py…
Jan 8, 2025
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: Support passing google.auth typed credentials in `initialize_…
…app()` (#821) * feat: Support passing `google.auth` typed credentials in `initialize_app()` * Refactor and add unit test
  • Loading branch information
jonathanedey authored Nov 4, 2024
commit 32e8dd284429f5dfbdaa21f6ac54f9d0698151cc
8 changes: 6 additions & 2 deletions firebase_admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import os
import threading

from google.auth.credentials import Credentials as GoogleAuthCredentials
from google.auth.exceptions import DefaultCredentialsError
from firebase_admin import credentials
from firebase_admin.__about__ import __version__
Expand Down Expand Up @@ -208,10 +209,13 @@ def __init__(self, name, credential, options):
'non-empty string.'.format(name))
self._name = name

if not isinstance(credential, credentials.Base):
if isinstance(credential, GoogleAuthCredentials):
self._credential = credentials._ExternalCredentials(credential) # pylint: disable=protected-access
elif isinstance(credential, credentials.Base):
self._credential = credential
else:
raise ValueError('Illegal Firebase credential provided. App must be initialized '
'with a valid credential instance.')
self._credential = credential
self._options = _AppOptions(options)
self._lock = threading.RLock()
self._services = {}
Expand Down
14 changes: 14 additions & 0 deletions firebase_admin/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import pathlib

import google.auth
from google.auth.credentials import Credentials as GoogleAuthCredentials
from google.auth.transport import requests
from google.oauth2 import credentials
from google.oauth2 import service_account
Expand Down Expand Up @@ -58,6 +59,19 @@ def get_credential(self):
"""Returns the Google credential instance used for authentication."""
raise NotImplementedError

class _ExternalCredentials(Base):
"""A wrapper for google.auth.credentials.Credentials typed credential instances"""

def __init__(self, credential: GoogleAuthCredentials):
super(_ExternalCredentials, self).__init__()
self._g_credential = credential

def get_credential(self):
"""Returns the underlying Google Credential

Returns:
google.auth.credentials.Credentials: A Google Auth credential instance."""
return self._g_credential

class Certificate(Base):
"""A credential initialized from a JSON certificate keyfile."""
Expand Down
10 changes: 10 additions & 0 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,16 @@ def test_non_default_app_init(self, app_credential):
with pytest.raises(ValueError):
firebase_admin.initialize_app(app_credential, name='myApp')

def test_app_init_with_google_auth_cred(self):
cred = testutils.MockGoogleCredential()
assert isinstance(cred, credentials.GoogleAuthCredentials)
app = firebase_admin.initialize_app(cred)
assert cred is app.credential.get_credential()
assert isinstance(app.credential, credentials.Base)
assert isinstance(app.credential, credentials._ExternalCredentials)
with pytest.raises(ValueError):
firebase_admin.initialize_app(app_credential)

@pytest.mark.parametrize('cred', invalid_credentials)
def test_app_init_with_invalid_credential(self, cred):
with pytest.raises(ValueError):
Expand Down