Skip to content

Commit be01081

Browse files
jamespb97mikehardy
authored andcommitted
fix(auth): add TotpSecret type definition
1 parent b6f3375 commit be01081

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

packages/auth/lib/index.d.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,52 @@ export namespace FirebaseAuthTypes {
275275
assertion(credential: AuthCredential): MultiFactorAssertion;
276276
}
277277

278+
/**
279+
* Represents a TOTP secret that is used for enrolling a TOTP second factor.
280+
* Contains the shared secret key and other parameters to generate time-based
281+
* one-time passwords. Implements methods to retrieve the shared secret key,
282+
* generate a QR code URL, and open the QR code URL in an OTP authenticator app.
283+
*
284+
* Differs from standard firebase JS implementation in three ways:
285+
* 1- there is no visibility into ony properties other than the secretKey
286+
* 2- there is an added `openInOtpApp` method supported by native SDKs
287+
* 3- the return value of generateQrCodeUrl is a Promise because react-native bridge is async
288+
* @public
289+
*/
290+
export declare class TotpSecret {
291+
/** used internally to support non-default auth instances */
292+
private readonly auth;
293+
/**
294+
* Shared secret key/seed used for enrolling in TOTP MFA and generating OTPs.
295+
*/
296+
readonly secretKey: string;
297+
298+
private constructor();
299+
300+
/**
301+
* Returns a QR code URL as described in
302+
* https://github.com/google/google-authenticator/wiki/Key-Uri-Format
303+
* This can be displayed to the user as a QR code to be scanned into a TOTP app like Google Authenticator.
304+
* If the optional parameters are unspecified, an accountName of userEmail and issuer of firebaseAppName are used.
305+
*
306+
* @param accountName the name of the account/app along with a user identifier.
307+
* @param issuer issuer of the TOTP (likely the app name).
308+
* @returns A Promise that resolves to a QR code URL string.
309+
*/
310+
async generateQrCodeUrl(accountName?: string, issuer?: string): Promise<string>;
311+
312+
/**
313+
* Opens the specified QR Code URL in an OTP authenticator app on the device.
314+
* The shared secret key and account name will be populated in the OTP authenticator app.
315+
* The URL uses the otpauth:// scheme and will be opened on an app that handles this scheme,
316+
* if it exists on the device, possibly opening the ecocystem-specific app store with a generic
317+
* query for compatible apps if no app exists on the device.
318+
*
319+
* @param qrCodeUrl the URL to open in the app, from generateQrCodeUrl
320+
*/
321+
openInOtpApp(qrCodeUrl: string): string;
322+
}
323+
278324
export interface TotpMultiFactorGenerator {
279325
FACTOR_ID: FactorId.TOTP;
280326

0 commit comments

Comments
 (0)