Skip to content

Commit 0f84366

Browse files
committed
Include a reference to AuthInternal in MultiFactorSessionImpl.
This is needed for TOTP support where the function to generate TOTP Secret (by invoking startEnrollment API) needs the Auth reference, but rather than pass in a parameter, we can derive it from the multiFactorSession that is already passed in as a param. This simplifies the API for the developer, by requiring one less paramter.
1 parent 87c90a7 commit 0f84366

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

packages/auth/src/mfa/mfa_session.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17+
import { AuthInternal } from '../model/auth';
1718
import { MultiFactorSession } from '../model/public_types';
1819

1920
export const enum MultiFactorSessionType {
@@ -31,11 +32,12 @@ interface SerializedMultiFactorSession {
3132
export class MultiFactorSessionImpl implements MultiFactorSession {
3233
private constructor(
3334
readonly type: MultiFactorSessionType,
34-
readonly credential: string
35+
readonly credential: string,
36+
readonly auth?: AuthInternal,
3537
) {}
3638

37-
static _fromIdtoken(idToken: string): MultiFactorSessionImpl {
38-
return new MultiFactorSessionImpl(MultiFactorSessionType.ENROLL, idToken);
39+
static _fromIdtoken(idToken: string, auth?: AuthInternal): MultiFactorSessionImpl {
40+
return new MultiFactorSessionImpl(MultiFactorSessionType.ENROLL, idToken, auth);
3941
}
4042

4143
static _fromMfaPendingCredential(

packages/auth/src/mfa/mfa_user.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ describe('core/mfa/mfa_user/MultiFactorUser', () => {
8484
expect(mfaSession.type).to.eq(MultiFactorSessionType.ENROLL);
8585
expect(mfaSession.credential).to.eq('access-token');
8686
});
87+
it('should contain a reference to auth', async () => {
88+
const mfaSession = (await mfaUser.getSession()) as MultiFactorSessionImpl;
89+
expect(mfaSession.type).to.eq(MultiFactorSessionType.ENROLL);
90+
expect(mfaSession.credential).to.eq('access-token');
91+
expect(mfaSession.auth).to.eq(auth);
92+
});
8793
});
8894

8995
describe('enroll', () => {

packages/auth/src/mfa/mfa_user.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class MultiFactorUserImpl implements MultiFactorUser {
4949
}
5050

5151
async getSession(): Promise<MultiFactorSession> {
52-
return MultiFactorSessionImpl._fromIdtoken(await this.user.getIdToken());
52+
return MultiFactorSessionImpl._fromIdtoken(await this.user.getIdToken(), this.user.auth);
5353
}
5454

5555
async enroll(

packages/auth/src/platform_browser/mfa/assertions/phone.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ describe('platform_browser/mfa/phone', () => {
5858

5959
describe('enroll', () => {
6060
beforeEach(() => {
61-
session = MultiFactorSessionImpl._fromIdtoken('enrollment-id-token');
61+
session = MultiFactorSessionImpl._fromIdtoken('enrollment-id-token', auth);
6262
});
6363

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

8081
context('with display name', () => {
@@ -97,6 +98,7 @@ describe('platform_browser/mfa/phone', () => {
9798
sessionInfo: 'verification-id'
9899
}
99100
});
101+
expect(session.auth).to.eql(auth);
100102
});
101103
});
102104
});
@@ -119,6 +121,7 @@ describe('platform_browser/mfa/phone', () => {
119121
sessionInfo: 'verification-id'
120122
}
121123
});
124+
expect(session.auth).to.eql(undefined);
122125
});
123126
});
124127
});

0 commit comments

Comments
 (0)