Skip to content

Include a reference to AuthInternal in MultiFactorSessionImpl. #6594

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

Merged
merged 2 commits into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions packages/auth/src/mfa/mfa_session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { AuthInternal } from '../model/auth';
import { MultiFactorSession } from '../model/public_types';

export const enum MultiFactorSessionType {
Expand All @@ -31,11 +32,19 @@ interface SerializedMultiFactorSession {
export class MultiFactorSessionImpl implements MultiFactorSession {
private constructor(
readonly type: MultiFactorSessionType,
readonly credential: string
readonly credential: string,
readonly auth?: AuthInternal
Copy link
Contributor

Choose a reason for hiding this comment

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

Wondering if this change need to be documented somewhere or any proto files need to be changed as we added a new param

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is an implementation detail, a developer will not directly interact with this field, hence it is not documented.

Copy link
Contributor

Choose a reason for hiding this comment

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

What about internal customers?

) {}

static _fromIdtoken(idToken: string): MultiFactorSessionImpl {
return new MultiFactorSessionImpl(MultiFactorSessionType.ENROLL, idToken);
static _fromIdtoken(
idToken: string,
auth?: AuthInternal
): MultiFactorSessionImpl {
return new MultiFactorSessionImpl(
MultiFactorSessionType.ENROLL,
idToken,
auth
);
}

static _fromMfaPendingCredential(
Expand Down
6 changes: 6 additions & 0 deletions packages/auth/src/mfa/mfa_user.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ describe('core/mfa/mfa_user/MultiFactorUser', () => {
expect(mfaSession.type).to.eq(MultiFactorSessionType.ENROLL);
expect(mfaSession.credential).to.eq('access-token');
});
it('should contain a reference to auth', async () => {
const mfaSession = (await mfaUser.getSession()) as MultiFactorSessionImpl;
expect(mfaSession.type).to.eq(MultiFactorSessionType.ENROLL);
expect(mfaSession.credential).to.eq('access-token');
expect(mfaSession.auth).to.eq(auth);
});
});

describe('enroll', () => {
Expand Down
5 changes: 4 additions & 1 deletion packages/auth/src/mfa/mfa_user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ export class MultiFactorUserImpl implements MultiFactorUser {
}

async getSession(): Promise<MultiFactorSession> {
return MultiFactorSessionImpl._fromIdtoken(await this.user.getIdToken());
return MultiFactorSessionImpl._fromIdtoken(
await this.user.getIdToken(),
this.user.auth
);
}

async enroll(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ describe('platform_browser/mfa/phone', () => {

describe('enroll', () => {
beforeEach(() => {
session = MultiFactorSessionImpl._fromIdtoken('enrollment-id-token');
session = MultiFactorSessionImpl._fromIdtoken(
'enrollment-id-token',
auth
);
});

it('should finalize the MFA enrollment', async () => {
Expand All @@ -75,6 +78,7 @@ describe('platform_browser/mfa/phone', () => {
sessionInfo: 'verification-id'
}
});
expect(session.auth).to.eql(auth);
});

context('with display name', () => {
Expand All @@ -97,6 +101,7 @@ describe('platform_browser/mfa/phone', () => {
sessionInfo: 'verification-id'
}
});
expect(session.auth).to.eql(auth);
});
});
});
Expand All @@ -119,6 +124,7 @@ describe('platform_browser/mfa/phone', () => {
sessionInfo: 'verification-id'
}
});
expect(session.auth).to.eql(undefined);
});
});
});
Expand Down