Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ scripts/apikey.txt
htmlcov/
.pytest_cache/
.vscode/
.DS_Store
27 changes: 27 additions & 0 deletions firebase_admin/_user_mgt.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,33 @@ def generate_email_action_link(self, action_type, email, action_code_settings=No
'Failed to generate email action link.', http_response=http_resp)
return body.get('oobLink')

def send_email_action_link(self, action_type, email, action_code_settings=None):
"""Sends an email of the given action type

Args:
action_type: String. Valid values ['VERIFY_EMAIL', 'EMAIL_SIGNIN', 'PASSWORD_RESET']
email: Email of the user to whom the email will be sent
action_code_settings: ``ActionCodeSettings`` object or dict (optional). Defines whether
the link is to be handled by a mobile app and the additional state information to be
passed in the deep link, etc.

Raises:
FirebaseError: If an error occurs while generating the link
ValueError: If the provided arguments are invalid
"""
payload = {
'requestType': _auth_utils.validate_action_type(action_type),
'email': _auth_utils.validate_email(email)
}

if action_code_settings:
payload.update(encode_action_code_settings(action_code_settings))
try:
self._client.body_and_response(
'post', '/accounts:sendOobCode', json=payload)
except requests.exceptions.RequestException as error:
raise _auth_utils.handle_auth_backend_error(error)


class _UserIterator(object):
"""An iterator that allows iterating over user accounts, one at a time.
Expand Down
56 changes: 56 additions & 0 deletions firebase_admin/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,25 @@ def generate_password_reset_link(email, action_code_settings=None, app=None):
return user_manager.generate_email_action_link(
'PASSWORD_RESET', email, action_code_settings=action_code_settings)

def send_password_reset_link(email, action_code_settings=None, app=None):
"""Sends an email with the out-of-band email action link for password reset
flows to the specified email address.

Args:
email: The email of the user whose password is to be reset.
action_code_settings: ``ActionCodeSettings`` instance (optional). Defines whether
the link is to be handled by a mobile app and the additional state information to be
passed in the deep link.
app: An App instance (optional).
Raises:
ValueError: If the provided arguments are invalid
FirebaseError: If an error occurs while generating the link
"""

user_manager = _get_auth_service(app).user_manager
user_manager.send_email_action_link(
'PASSWORD_RESET', email, action_code_settings=action_code_settings)


def generate_email_verification_link(email, action_code_settings=None, app=None):
"""Generates the out-of-band email action link for email verification flows for the specified
Expand All @@ -513,6 +532,25 @@ def generate_email_verification_link(email, action_code_settings=None, app=None)
return user_manager.generate_email_action_link(
'VERIFY_EMAIL', email, action_code_settings=action_code_settings)

def send_email_verification_link(email, action_code_settings=None, app=None):
"""Sends an email with the out-of-band email action link for email verification
flows to the specified email address.

Args:
email: The email of the user to be verified.
action_code_settings: ``ActionCodeSettings`` instance (optional). Defines whether
the link is to be handled by a mobile app and the additional state information to be
passed in the deep link.
app: An App instance (optional).
Raises:
ValueError: If the provided arguments are invalid
FirebaseError: If an error occurs while generating the link
"""

user_manager = _get_auth_service(app).user_manager
user_manager.send_email_action_link(
'VERIFY_EMAIL', email, action_code_settings=action_code_settings)


def generate_sign_in_with_email_link(email, action_code_settings, app=None):
"""Generates the out-of-band email action link for email link sign-in flows, using the action
Expand All @@ -535,6 +573,24 @@ def generate_sign_in_with_email_link(email, action_code_settings, app=None):
return user_manager.generate_email_action_link(
'EMAIL_SIGNIN', email, action_code_settings=action_code_settings)

def send_sign_in_with_email_link(email, action_code_settings=None, app=None):
"""Sends an email with the out-of-band email action link for email link sign-in
flows to the specified email address.

Args:
email: The email of the user signing in.
action_code_settings: ``ActionCodeSettings`` instance (optional). Defines whether
the link is to be handled by a mobile app and the additional state information to be
passed in the deep link.
app: An App instance (optional).
Raises:
ValueError: If the provided arguments are invalid
FirebaseError: If an error occurs while generating the link
"""

user_manager = _get_auth_service(app).user_manager
user_manager.send_email_action_link(
'EMAIL_SIGNIN', email, action_code_settings=action_code_settings)

def _check_jwt_revoked(verified_claims, exc_type, label, app):
user = get_user(verified_claims.get('uid'), app=app)
Expand Down