Skip to content

Commit 2fb370f

Browse files
authored
feat: add email and password change functionality
commit f1b7f2b Author: Asif Arman Rahman <[email protected]> Date: Sun Aug 20 19:26:29 2023 +0600 docs(auth): guide update * change_email * change_password commit 31df27d Author: Vladislav Dashtu <[email protected]> Date: Tue Aug 15 22:47:43 2023 +0400 mistake in change_email description commit 44092c2 Author: Vladislav Dashtu <[email protected]> Date: Tue Aug 15 22:43:12 2023 +0400 added change_email and change_password methods resolves #20
1 parent 25451c3 commit 2fb370f

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

docs/guide/authentication.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,32 @@ Update stored information or add information into the user's account.
291291
..
292292
293293

294+
change_email
295+
--------------
296+
297+
Change the email associated with the user's account.
298+
299+
.. code-block:: python
300+
301+
# change user's email
302+
auth.change_email(user['idToken'], email='[email protected]')
303+
304+
..
305+
306+
307+
change_password
308+
--------------
309+
310+
Change the password associated with the user's account.
311+
312+
.. code-block:: python
313+
314+
# change user's password
315+
auth.change_password(user['idToken'], password='iLoveYou3000')
316+
317+
..
318+
319+
294320
refresh
295321
-------
296322

firebase/auth/__init__.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,62 @@ def _token_from_auth_url(self, url):
521521
'type': 'id_token',
522522
'value': request_object.json()['id_token'],
523523
}
524+
525+
def change_email(self, id_token, email):
526+
""" Changes a user's email
527+
528+
| For more details:
529+
| `Firebase Auth REST API | section-change-email`_
530+
531+
.. _Firebase Auth REST API | section-change-email: https://firebase.google.com/docs/reference/rest/auth#section-change-email
532+
533+
:type id_token: str
534+
:param id_token: A Firebase Auth ID token for the user.
535+
536+
:type email: str
537+
:param email: User's new email.
538+
539+
:return: UserInfo and Firebase Auth Tokens.
540+
:rtype: dict
541+
"""
542+
543+
request_ref = "https://www.googleapis.com/identitytoolkit/v3/relyingparty/setAccountInfo?key={0}".format(self.api_key)
544+
545+
headers = {"content-type": "application/json; charset=UTF-8"}
546+
data = json.dumps({"idToken": id_token, "email": email, "returnSecureToken": True})
547+
request_object = self.requests.post(request_ref, headers=headers, data=data)
548+
549+
raise_detailed_error(request_object)
550+
551+
return request_object.json()
552+
553+
def change_password(self, id_token, password):
554+
""" Changes a user's password
555+
556+
| For more details:
557+
| `Firebase Auth REST API | section-change-password`_
558+
559+
.. _Firebase Auth REST API | section-change-password: https://firebase.google.com/docs/reference/rest/auth#section-change-password
560+
561+
:type id_token: str
562+
:param id_token: A Firebase Auth ID token for the user.
563+
564+
:type password: str
565+
:param password: User's new password.
566+
567+
:return: UserInfo and Firebase Auth Tokens.
568+
:rtype: dict
569+
"""
570+
571+
request_ref = "https://www.googleapis.com/identitytoolkit/v3/relyingparty/setAccountInfo?key={0}".format(self.api_key)
572+
573+
headers = {"content-type": "application/json; charset=UTF-8"}
574+
data = json.dumps({"idToken": id_token, "password": password, "returnSecureToken": True})
575+
request_object = self.requests.post(request_ref, headers=headers, data=data)
576+
577+
raise_detailed_error(request_object)
578+
579+
return request_object.json()
524580

525581
def update_profile(self, id_token, display_name=None, photo_url=None, delete_attribute=None):
526582
""" Update a user's profile (display name / photo URL).

0 commit comments

Comments
 (0)