Skip to content

UserNotFoundError is not raised as expected. Instead, UnexpectedResponseError is raised. #813

Open
@evan-hitobito

Description

@evan-hitobito

[READ] Step 1: Are you in the right place?

  • For issues related to the code in this repository file a GitHub issue.
  • If the issue pertains to Cloud Firestore, report directly in the
    Python Firestore GitHub repo. Firestore
    bugs reported in this repo will be closed with a reference to the Python Firestore
    project.
  • For general technical questions, post a question on StackOverflow
    with the firebase tag.
  • For general Firebase discussion, use the firebase-talk
    google group.
  • For help troubleshooting your application that does not fall under one
    of the above categories, reach out to the personalized
    Firebase support channel.

[REQUIRED] Step 2: Describe your environment

  • Operating System version: 14.2.1(23C71)
  • Firebase SDK version: 6.3.0
  • Firebase Product: auth
  • Python version:3.12.0
  • Pip version: 24.0

[REQUIRED] Step 3: Describe the problem

When calling the generate_password_reset_link, we got errors Failed to generate email action link. which is raised in _auth_utils.UnexpectedResponseError.
We expect UserNotFoundError to be raised if the email in request is not in authentication list.

Steps to reproduce:

What happened? How can we make the problem occur?
This could be a description, log/console output, etc.

Calling generate_password_reset_link with invalid email

Relevant Code:

def reset_password(
        self, request: PostResetPasswordRequest, lang: str, client: MailjetClient
    ):
        try:
            password_link = auth.generate_password_reset_link(request.email)
        except auth.UserNotFoundError:
            # For security reasons, we don't want to reveal whether the email exists or not
            logging.info(
                f"Password reset request for non-existing email: {request.email}"
            )
            return None

        except Exception as e:
            logging.error(f"Failed to accept password reset request: {e}")
            return None
def generate_email_action_link(self, action_type, email, action_code_settings=None):
        """Fetches the email action links for types

        Args:
            action_type: String. Valid values ['VERIFY_EMAIL', 'EMAIL_SIGNIN', 'PASSWORD_RESET']
            email: Email of the user for which the action is performed
            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.
        Returns:
            link_url: action url to be emailed to the user

        Raises:
            UnexpectedResponseError: If the backend server responds with an unexpected message
            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),
            'returnOobLink': True
        }

        if action_code_settings:
            payload.update(encode_action_code_settings(action_code_settings))

        body, http_resp = self._make_request('post', '/accounts:sendOobCode', json=payload)
        if not body or not body.get('oobLink'):
            raise _auth_utils.UnexpectedResponseError(
                'Failed to generate email action link.', http_response=http_resp)
        return body.get('oobLink')

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions