diff --git a/.gitignore b/.gitignore index 4880bc525..8187baefa 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ scripts/apikey.txt htmlcov/ .pytest_cache/ .vscode/ +.DS_Store diff --git a/firebase_admin/_user_mgt.py b/firebase_admin/_user_mgt.py index 2e10fac1b..f38542f79 100644 --- a/firebase_admin/_user_mgt.py +++ b/firebase_admin/_user_mgt.py @@ -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. diff --git a/firebase_admin/auth.py b/firebase_admin/auth.py index a5110c211..c26a6b933 100644 --- a/firebase_admin/auth.py +++ b/firebase_admin/auth.py @@ -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 @@ -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 @@ -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)