-
Notifications
You must be signed in to change notification settings - Fork 409
feat: add basic fpnv #3030
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: fpnv
Are you sure you want to change the base?
feat: add basic fpnv #3030
Conversation
Summary of ChangesHello @boikoa-gl, 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 introduces a new Firebase Phone Number Verification (FPNV) module into the Firebase Admin SDK. This feature enables developers to verify phone number tokens, similar to how existing ID tokens are handled. The changes involve adding the necessary service classes, integrating them into the SDK's public API and build configuration, and establishing robust token verification logic, including custom error handling and support for the ES256 JWT algorithm. 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 introduces a new fpnv (Firebase Phone Number Verification) service. The overall structure is good and follows the existing patterns in the SDK. However, there are a few critical issues that need to be addressed before merging. The error handling for this new service is incomplete, with placeholder error codes in FpnvErrorCode. This will lead to incorrect error reporting. I've provided a suggestion for a more complete implementation. There's also a potential bug in the JWT audience (aud) claim verification that could cause a runtime error. Finally, I've made some suggestions to use more specific error codes to improve the developer experience. Please review the detailed comments.
lahirumaramba
left a comment
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.
Thanks! Added a few comments. Please check the CI errors.
Run npm run api-extractor:local to generate apidocs and update the PR with the new files.
lahirumaramba
left a comment
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.
Thanks! It is looking good!
Added a few more comments
| private readonly app_: App; | ||
|
|
||
| protected readonly fpnvVerifier: FirebasePhoneNumberTokenVerifier; | ||
|
|
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.
| /** | |
| * @param app - The app for this `Fpnv` service. | |
| * @constructor | |
| * @internal | |
| */ |
| * Fpnv service bound to the provided app. | ||
| */ | ||
| export class Fpnv { | ||
| private readonly app_: App; |
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.
nit: you can simplify this by using constructor parameter properties.
constructor(readonly app: App) { ...
// this.app| /** | ||
| * Returns the app associated with this Auth instance. | ||
| * | ||
| * @returns The app associated with this Auth instance. |
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.
Did you mean Fpnv instance here?
| * | ||
| * @returns The app associated with this Auth instance. | ||
| */ | ||
| get app(): App { |
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.
Is this used for anything? If not, we can probably remove this getter
| return this.app_; | ||
| } | ||
|
|
||
| public async verifyToken(idToken: string): Promise<FpnvToken> { |
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.
Is this really an idToken?
|
|
||
| export function createFPNTVerifier(app: App): FirebasePhoneNumberTokenVerifier { | ||
| return new FirebasePhoneNumberTokenVerifier( | ||
| CLIENT_CERT_URL, |
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.
Do we expect these to change in the future? If not, I don't think we would need a factory here. FirebasePhoneNumberTokenVerifier already has access to these consts. If you have used the auth token verification code as an example for this, we use a factory method there because we support two different token types (custom token and session tokens)
| constructor(app: App) { | ||
|
|
||
| this.app_ = app; | ||
| this.fpnvVerifier = createFPNTVerifier(app); |
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.
Can this be simplified to a new FirebasePhoneNumberTokenVerifier(app)?
| // (undocumented) | ||
| iss: string; | ||
| // (undocumented) | ||
| sub: string; |
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.
Please add documentation to these types. For example see:
| * The audience for which this token is intended. |
| return this.app_; | ||
| } | ||
|
|
||
| public async verifyToken(idToken: string): Promise<FpnvToken> { |
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.
| public async verifyToken(idToken: string): Promise<FpnvToken> { | |
| public async verifyToken(fpnvJwt: string): Promise<FpnvToken> { |
| get app(): App { | ||
| return this.app_; | ||
| } | ||
|
|
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.
Missing documentation here
Hey there! So you want to contribute to a Firebase SDK?
Before you file this pull request, please read these guidelines:
Discussion
If not, go file an issue about this before creating a pull request to discuss.
Testing
API Changes
us make Firebase APIs better, please propose your change in an issue so that we
can discuss it together.