Skip to content

Commit e5ea84e

Browse files
feat(auth): client secret from file
1️⃣ social provider client secrets can now be directly read from json files.
1 parent b9cff88 commit e5ea84e

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

firebase/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,10 @@ def auth(self, client_secret=None):
5656
instance.
5757
5858
:type client_secret: str or dict
59-
:param client_secret: (Optional) Dict object from social
60-
client secret file, defaults to :data:`None`.
59+
:param client_secret: (Optional) File path to or the dict
60+
object from social client secret file, defaults to
61+
:data:`None`.
62+
6163
6264
:return: A newly initialized instance of Auth.
6365
:rtype: Auth

firebase/auth/__init__.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ class Auth:
3333
:param requests: Session to make HTTP requests
3434
3535
:type client_secret: str or dict
36-
:param client_secret: (Optional) Dict object from social client
37-
secret file, defaults to :data:`None`.
36+
:param client_secret: (Optional) File path to or the dict object
37+
from social client secret file, defaults to :data:`None`.
38+
3839
"""
3940

4041
def __init__(self, api_key, credentials, requests, client_secret=None):
@@ -49,7 +50,7 @@ def __init__(self, api_key, credentials, requests, client_secret=None):
4950
self.session_id = None
5051

5152
if client_secret:
52-
self.client_secret = client_secret
53+
self.client_secret = _load_client_secret(client_secret)
5354

5455
def create_authentication_uri(self, provider_id):
5556
""" Creates an authentication URI for the given social
@@ -446,3 +447,22 @@ def update_profile(self, id_token, display_name=None, photo_url=None, delete_att
446447
raise_detailed_error(request_object)
447448

448449
return request_object.json()
450+
451+
452+
def _load_client_secret(secret):
453+
""" Load social providers' client secret from file if file path
454+
provided.
455+
456+
:type secret: str or dict
457+
:param secret: File path to or the dict object from social client
458+
secret file.
459+
460+
:return: social client secret
461+
:rtype: dict
462+
"""
463+
464+
if type(secret) is str:
465+
with open(secret) as file:
466+
secret = json.load(file)
467+
468+
return secret

0 commit comments

Comments
 (0)