Skip to content

Extends createUser to support multi-factor user creation. - #718

Merged
bojeil-google merged 3 commits into
auth-mfafrom
auth-mfa-temp
Dec 10, 2019
Merged

Extends createUser to support multi-factor user creation.#718
bojeil-google merged 3 commits into
auth-mfafrom
auth-mfa-temp

Conversation

@bojeil-google

Copy link
Copy Markdown
Contributor

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.

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.

@hiranya911hiranya911 left a comment

Copy link
Copy Markdown
Contributor

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.

Comment threadsrc/auth/auth-api-request.ts Outdated
} catch (e) {
return Promise.reject(e);
}
if (request.mfaInfo.length === 0) {

Copy link
Copy Markdown
Contributor

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;
}

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment threadsrc/auth/auth-api-request.ts Outdated
}
// Construct mfa related user data.
if (validator.isNonNullObject(request.multiFactor)) {
if (validator.isArray(request.multiFactor.enrolledFactors)) {

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment threadtest/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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const firstFactor = enrolledFactors[0];

Copy link
Copy Markdown
ContributorAuthor

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.

Comment threadtest/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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const secondFactor = enrolledFactors[1];

Copy link
Copy Markdown
ContributorAuthor

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', () => {

Copy link
Copy Markdown
Contributor

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) => {
...
});

Copy link
Copy Markdown
ContributorAuthor

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',

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@hiranya911hiranya911 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bojeil-google

Copy link
Copy Markdown
ContributorAuthor

Thanks for the quick review!

@bojeil-google
bojeil-google merged commit b59b17a into auth-mfaDec 10, 2019
@bojeil-google
bojeil-google deleted the auth-mfa-temp branch December 10, 2019 22:48
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@bojeil-google@hiranya911