-
Notifications
You must be signed in to change notification settings - Fork 389
Extends createUser to support multi-factor user creation. #718
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
Conversation
Note that only phoneNumber and displayName are allowed to be passed in this operation. Adds relevant unit and integration tests. This capability is only available in staging.
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.
Looks pretty good. Just a few nits to improve on.
src/auth/auth-api-request.ts
Outdated
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
if (request.mfaInfo.length === 0) { |
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: To keep the mutations to request
to a minimum, you can do this:
const mfaInfo = [];
// Populate mfaInfo
if (request.mfaInfo.length > 0) {
// You can drop the if condition, if you checked for isNonEmptyArray earlier.
request.mfaInfo = mfaInfo;
}
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.
Done
src/auth/auth-api-request.ts
Outdated
@@ -1145,6 +1162,34 @@ export abstract class AbstractAuthRequestHandler { | |||
request.localId = request.uid; | |||
delete request.uid; | |||
} | |||
// Construct mfa related user data. | |||
if (validator.isNonNullObject(request.multiFactor)) { | |||
if (validator.isArray(request.multiFactor.enrolledFactors)) { |
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.
isNonEmptyArray makes more sense here.
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.
Done
test/integration/auth.spec.ts
Outdated
// Confirm second factors added to user. | ||
expect(userRecord.multiFactor.enrolledFactors.length).to.equal(2); | ||
// Confirm first enrolled second factor. | ||
expect(userRecord.multiFactor.enrolledFactors[0].uid).not.to.be.undefined; |
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.
const firstFactor = enrolledFactors[0];
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.
I set firstMultiFactor
to userRecord.multiFactor.enrolledFactors[0]
. That improves readability.
test/integration/auth.spec.ts
Outdated
expect(userRecord.multiFactor.enrolledFactors[0].factorId) | ||
.to.equal(enrolledFactors[0].factorId); | ||
// Confirm second enrolled second factor. | ||
expect(userRecord.multiFactor.enrolledFactors[1].uid).not.to.be.undefined; |
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.
const secondFactor = enrolledFactors[1];
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.
I set secondMultiFactor
to userRecord.multiFactor.enrolledFactors[1]
. It is easier to read this way.
}); | ||
}); | ||
|
||
it('should be fulfilled given empty enrolled factors array', () => { |
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 seems identical to the previous test case. Can we consolidate with an array?
const noEnrolledFactors = [ [], null ];
noEnrolledFactors.forEach((arg) => {
...
});
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.
Done
const unsupportedSecondFactor = { | ||
secret: 'SECRET', | ||
displayName: 'Google Authenticator on personal phone', | ||
factorId: 'totp', |
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.
Add a comment here indicating totp is not yet supported.
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.
Done
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.
LGTM
Thanks for the quick review! |
Extends createUser to support multi-factor user creation.
Note that only phoneNumber and displayName are allowed to be passed in this operation.
Adds relevant unit and integration tests.
This capability is only available in staging.