Skip to content

Commit e509924

Browse files
committed
feat(auth): support native TOTP app open
1 parent e32b6ce commit e509924

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

packages/auth/android/src/main/java/io/invertase/firebase/auth/ReactNativeFirebaseAuthModule.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,6 +1322,14 @@ public void generateQrCodeUrl(
13221322
promise.resolve(secret.generateQrCodeUrl(account, issuer));
13231323
}
13241324

1325+
@ReactMethod
1326+
public void openInOtpApp(final String appName, final String secretKey, final String qrCodeUri) {
1327+
TotpSecret secret = mTotpSecrets.get(secretKey);
1328+
if (secret != null) {
1329+
secret.openInOtpApp(qrCodeUri);
1330+
}
1331+
}
1332+
13251333
@ReactMethod
13261334
public void finalizeTotpEnrollment(
13271335
final String appName,

packages/auth/ios/RNFBAuth/RNFBAuthModule.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,16 @@ - (void)invalidate {
10411041
resolve(url);
10421042
}
10431043

1044+
RCT_EXPORT_METHOD(openInOtpApp
1045+
: (FIRApp *)firebaseApp
1046+
: (NSString *)secretKey
1047+
: (NSString *)qrCodeUri) {
1048+
DLog(@"generateQrCodeUrl using secretKey: %@", secretKey);
1049+
FIRTOTPSecret *totpSecret = cachedTotpSecrets[secretKey];
1050+
DLog(@"openInOtpApp using qrCodeUri: %@", qrCodeUri);
1051+
[totpSecret openInOTPAppWithQRCodeURL:qrCodeUri];
1052+
}
1053+
10441054
RCT_EXPORT_METHOD(getSession
10451055
: (FIRApp *)firebaseApp
10461056
: (RCTPromiseResolveBlock)resolve

packages/auth/lib/TotpSecret.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,19 @@ export class TotpSecret {
4949
}
5050
return this.auth.native.generateQrCodeUrl(this.secretKey, accountName, issuer);
5151
}
52+
53+
/**
54+
* Opens the specified QR Code URL in an OTP authenticator app on the device.
55+
* The shared secret key and account name will be populated in the OTP authenticator app.
56+
* The URL uses the otpauth:// scheme and will be opened on an app that handles this scheme,
57+
* if it exists on the device, possibly opening the ecocystem-specific app store with a generic
58+
* query for compatible apps if no app exists on the device.
59+
*
60+
* @param qrCodeUrl the URL to open in the app, from generateQrCodeUrl
61+
*/
62+
openInOtpApp(qrCodeUrl) {
63+
if (isString(qrCodeUrl) && !qrCodeUrl !== '') {
64+
return this.auth.native.openInOtpApp(this.secretKey, qrCodeUrl);
65+
}
66+
}
5267
}

0 commit comments

Comments
 (0)