-
Notifications
You must be signed in to change notification settings - Fork 410
fix: Invalid provider UID handling in federated user lookup #3034
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @demolaf, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses an inconsistency in the authentication module's error handling. It refines the validation logic for federated user lookups, specifically ensuring that an empty federated user ID ( Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request improves error handling in getAccountInfoByFederatedUid by throwing a more specific error, auth/invalid-uid, when an empty provider UID (rawId) is provided. This is a good change that improves diagnostics for developers.
I've added two comments:
- A suggestion to improve the clarity of a test case description in
test/unit/auth/auth.spec.ts. - A note in
src/auth/auth-api-request.tsabout a remaining inconsistency in error handling for provider UIDs in another part of the API (getUsers), which could be addressed in a follow-up.
Also, please note that the pull request description mentions the new error code is auth/invalid-provider-uid, but the implementation correctly uses auth/invalid-uid to align with validateProviderUserInfo. This seems like a minor typo in the description.
Overall, the changes are correct and beneficial.
| if (!validator.isNonEmptyString(rawId)) { | ||
| throw new FirebaseAuthError(AuthClientErrorCode.INVALID_UID); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change correctly throws a more specific INVALID_UID error for an empty rawId, aligning with validateProviderUserInfo as mentioned in the pull request description. However, there seems to be another inconsistency in the codebase. The addProviderToRequest function (line 1051) throws AuthClientErrorCode.INVALID_PROVIDER_UID for an empty providerUid. This function is used by getUsers().
This means auth.getUserByProviderUid('a', '') will throw auth/invalid-uid, while auth.getUsers([{providerId: 'a', providerUid: ''}]) will throw auth/invalid-provider-uid.
While fixing this might be outside the scope of this PR, it would be good to create a follow-up issue to make these error codes consistent across the API for a better developer experience.
| }); | ||
|
|
||
| it('should be rejected given an invalid provider uid', () => { | ||
| it('should be rejected given an invalid uid', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test description was changed from "should be rejected given an invalid provider uid" to "should be rejected given an invalid uid". The former is more descriptive and less ambiguous, as "uid" could be misinterpreted as the Firebase user UID, whereas this test is specifically for the provider-specific UID. I suggest reverting to the more specific description to improve test clarity.
| it('should be rejected given an invalid uid', () => { | |
| it('should be rejected given an invalid provider uid', () => { |
|
A similar PR was created here #2305 |
Align federated UID validation with the rest of Auth requests. When getAccountInfoByFederatedUid receives an empty provider UID, it now returns auth/invalid-provider-uid (previously incorrectly auth/invalid-provider-id), matching validateProviderUserInfo.
Unit test updated accordingly.