Skip to content

Commit e06d906

Browse files
authored
Include a reference to AuthInternal in MultiFactorSessionImpl. (#6594)
* 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. * Added changeset.
1 parent 7c0c640 commit e06d906

File tree

5 files changed

+34
-5
lines changed

5 files changed

+34
-5
lines changed

.changeset/curly-mirrors-occur.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@firebase/auth': patch
3+
---
4+
5+
Included a reference to AuthInternal in MultiFactorSessionImpl.

packages/auth/src/mfa/mfa_session.ts

Lines changed: 12 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,19 @@ 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(
40+
idToken: string,
41+
auth?: AuthInternal
42+
): MultiFactorSessionImpl {
43+
return new MultiFactorSessionImpl(
44+
MultiFactorSessionType.ENROLL,
45+
idToken,
46+
auth
47+
);
3948
}
4049

4150
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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ export class MultiFactorUserImpl implements MultiFactorUser {
4949
}
5050

5151
async getSession(): Promise<MultiFactorSession> {
52-
return MultiFactorSessionImpl._fromIdtoken(await this.user.getIdToken());
52+
return MultiFactorSessionImpl._fromIdtoken(
53+
await this.user.getIdToken(),
54+
this.user.auth
55+
);
5356
}
5457

5558
async enroll(

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

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

5959
describe('enroll', () => {
6060
beforeEach(() => {
61-
session = MultiFactorSessionImpl._fromIdtoken('enrollment-id-token');
61+
session = MultiFactorSessionImpl._fromIdtoken(
62+
'enrollment-id-token',
63+
auth
64+
);
6265
});
6366

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

8084
context('with display name', () => {
@@ -97,6 +101,7 @@ describe('platform_browser/mfa/phone', () => {
97101
sessionInfo: 'verification-id'
98102
}
99103
});
104+
expect(session.auth).to.eql(auth);
100105
});
101106
});
102107
});
@@ -119,6 +124,7 @@ describe('platform_browser/mfa/phone', () => {
119124
sessionInfo: 'verification-id'
120125
}
121126
});
127+
expect(session.auth).to.eql(undefined);
122128
});
123129
});
124130
});

0 commit comments

Comments
 (0)