firebase / firebase/firebase-admin-python

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

Đang mở
#813 1 bình luận 0 reaction 1 người được giao Được @jonathanedey nhận Xem trên GitHub
api: auth
Ngôn ngữ chính
Python
Star
1.2k
Fork
359
Merge trung bình
5 ngày 6 phút
Pull request đã merge (30 ngày)
2

Mô tả

### [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](https://github.com/googleapis/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](http://stackoverflow.com/)
with the `firebase` tag.
* For general Firebase discussion, use the [firebase-talk](https://groups.google.com/forum/#!forum/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](https://firebase.google.com/support/).

### [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')
```

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.