Skip to content

Commit e69218e

Browse files
committed
adding support TOTP MFA
1 parent 47895fe commit e69218e

File tree

4 files changed

+120
-1
lines changed

4 files changed

+120
-1
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
2+
import { TotpSecret } from "../../platform_browser/mfa/assertions/totp";
3+
import { TotpMultiFactorAssertion } from "../../model/public_types";
4+
import { MultiFactorSession } from "../../model/public_types";
5+
/**
6+
* Provider for generating a {@link TotpMultiFactorAssertion}.
7+
*
8+
* @public
9+
*/
10+
11+
export class TotpMultiFactorGenerator {
12+
/**
13+
* Provides a {@link TotpMultiFactorAssertion} to confirm ownership of the totp(Time-based One Time Password) second factor.
14+
* This assertion is used to complete enrollment in TOTP second factor.
15+
*
16+
* @param secret {@link TotpSecret}.
17+
* @param oneTimePassword One-time password from TOTP App.
18+
* @returns A {@link TotpMultiFactorAssertion} which can be used with
19+
* {@link MultiFactorUser.enroll}.
20+
*/
21+
22+
static assertionForEnrollment(secret: TotpSecret, oneTimePassword: string): TotpMultiFactorAssertion {}
23+
24+
/**
25+
* Provides a {@link TotpMultiFactorAssertion} to confirm ownership of the totp second factor.
26+
* This assertion is used to complete signIn with TOTP as the second factor.
27+
*
28+
* @param enrollmentId identifies the enrolled TOTP second factor.
29+
* @param otp One-time password from TOTP App.
30+
* @returns A {@link TotpMultiFactorAssertion} which can be used with
31+
* {@link MultiFactorResolver.resolveSignIn}.
32+
*/
33+
34+
static assertionForSignIn(enrollmentId: string, otp: string): TotpMultiFactorAssertion {}
35+
36+
/**
37+
* Returns a promise to {@link TOTPSecret} which contains the TOTP shared secret key and other parameters.
38+
* Creates a TOTP secret as part of enrolling a TOTP second factor.
39+
* Used for generating a QRCode URL or inputting into a TOTP App.
40+
* This method uses the auth instance corresponding to the user in the multiFactorSession.
41+
*
42+
* @param session A link to {@MultiFactorSession}.
43+
* @returns A promise to {@link TotpSecret}.
44+
*/
45+
async static generateSecret(session: MultiFactorSession): Promise<TotpSecret> {}
46+
47+
/**
48+
* The identifier of the phone second factor: `totp`.
49+
*/
50+
static FACTOR_ID = FactorId.TOTP;
51+
}
52+
53+

packages/auth/src/model/enum_maps.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
*/
2323
export const FactorId = {
2424
/** Phone as second factor */
25-
PHONE: 'phone'
25+
PHONE: 'phone',
26+
TOTP: 'totp'
2627
} as const;
2728

2829
/**

packages/auth/src/model/public_types.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,3 +1227,12 @@ export interface Dependencies {
12271227
*/
12281228
errorMap?: AuthErrorMap;
12291229
}
1230+
1231+
/**
1232+
* The class for asserting ownership of a totp second factor. Provided by
1233+
* {@link TotpMultiFactorGenerator.assertion}.
1234+
*
1235+
* @public
1236+
*/
1237+
1238+
export interface TotpMultiFactorAssertion extends MultiFactorAssertion {}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* Stores the shared secret key and other parameters to generate time-based OTPs.
3+
* Implements methods to retrieve the shared secret key, generate a QRCode URL.
4+
*/
5+
6+
export class TotpSecret {
7+
/**
8+
* Returns the shared secret key/seed used to generate time-based one-time passwords.
9+
*
10+
* @returns Shared secret key/seed used for enrolling in TOTP MFA and generating otps.
11+
*/
12+
sharedSecretKey(): string {
13+
return this.secretKey;
14+
}
15+
16+
/**
17+
* Returns the hashing algorithm used to generate time-based one-time passwords.
18+
*
19+
* @returns Hashing algorithm used.
20+
*/
21+
hashingAlgorithm(): string {
22+
return this.hashingAlgorithm;
23+
}
24+
25+
/**
26+
* Returns the length of the OTP codes to be generated.
27+
*
28+
* @returns Length of the one-time passwords to be generated.
29+
*/
30+
codeLength(): number {
31+
return this.codeLength;
32+
}
33+
34+
/**
35+
* Returns the interval(in seconds) when the OTP codes should change.
36+
*
37+
* @returns The interval (in seconds) when the OTP codes should change.
38+
*/
39+
codeIntervalSeconds(): number {
40+
return this.codeIntervalSeconds;
41+
}
42+
43+
/**
44+
* Returns a QRCode URL as described in
45+
* https://github.com/google/google-authenticator/wiki/Key-Uri-Format
46+
* This can be displayed to the user as a QRCode to be scanned into a TOTP App like Google Authenticator.
47+
* If the optional parameters are unspecified, an accountName of "<firebaseAppName>:<userEmail> and issuer of <firebaseAppName> are used.
48+
*
49+
* @param accountName the name of the account/app along with a user identifier.
50+
* @param issuer issuer of the TOTP(likely the app name).
51+
* @returns A QRCode URL string.
52+
*/
53+
54+
generateQrCodeUrl(accountName?: string, issuer?: string): string {}
55+
}
56+

0 commit comments

Comments
 (0)