Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Copy TOTP to clipboard after passkey authentication in iOS (#2305)

Leendert de Borst53f456e22894
diff --git a/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Credential.swift b/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Credential.swift
index d9031c57a..5ad790183 100644
--- a/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Credential.swift
+++ b/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Credential.swift
@@ -128,13 +128,7 @@ extension CredentialProviderViewController: CredentialProviderDelegate {
// copy-on-fill setting enabled (default), put the current
// TOTP code on the clipboard so they can paste it into the
// 2FA field after the autofill completes.
- if matchingCredential.hasTotp,
- let secret = matchingCredential.totpSecret,
- AutofillSettings.shouldCopyTotpOnFill,
- let code = TotpGenerator.generateCode(secret: secret),
- !code.isEmpty {
- UIPasteboard.general.string = code
- }
+ TotpClipboard.copyCodeIfEnabled(secret: matchingCredential.totpSecret)
// Use the identifier that matches the credential identity
let identifier = request.credentialIdentity.user
diff --git a/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Passkey.swift b/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Passkey.swift
index 7776a3d84..8c8fb660f 100644
--- a/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Passkey.swift
+++ b/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Passkey.swift
@@ -3,6 +3,7 @@ import SwiftUI
import VaultStoreKit
import VaultUI
import VaultModels
+import VaultUtils
import CryptoKit
/**
@@ -84,6 +85,11 @@ extension CredentialProviderViewController: PasskeyProviderDelegate {
prfSecret: passkey.prfKey
)
+ // If the item behind this passkey also has a TOTP code and the user has the
+ // copy-on-fill setting enabled (default), put the current code on the clipboard.
+ let totpSecret = (try? vaultStore.getFirstTotpCode(forItemId: passkey.parentItemId))??.secretKey
+ TotpClipboard.copyCodeIfEnabled(secret: totpSecret)
+
// Build extension output if PRF results are available (iOS 18+)
if #available(iOS 18.0, *), let prfResults = assertion.prfResults {
// Convert Data to SymmetricKey for PRF output
@@ -653,6 +659,10 @@ extension CredentialProviderViewController: PasskeyProviderDelegate {
return
}
+ // If the credential also has a TOTP code and the user has the copy-on-fill setting
+ // enabled (default), put the current code on the clipboard.
+ TotpClipboard.copyCodeIfEnabled(secret: credential.totpSecret)
+
// Extract PRF inputs from the passkey request if available
var prfInputs: PrfInputs?
if #available(iOS 18.0, *), let extensionInput = self.currentPasskeyRequest?.extensionInput {
diff --git a/apps/mobile-app/ios/Podfile.lock b/apps/mobile-app/ios/Podfile.lock
index 64379a423..70229e41a 100644
--- a/apps/mobile-app/ios/Podfile.lock
+++ b/apps/mobile-app/ios/Podfile.lock
@@ -2768,7 +2768,7 @@ SPEC CHECKSUMS:
ExpoUI: b8da9e23eb4cef30e4797bc6de102a9178e6cd2b
ExpoWebBrowser: 6e3d90e3fe1952d21a8494872b1e1a485cd50e2f
FBLazyVector: 24e62c765683b8d89006a88a2c8f5cf019f0074d
- hermes-engine: a384bd37273f335daf0965c0fd0aa46f197e0175
+ hermes-engine: f684a01742a30bb5d7332da47aa184074d8ae9b4
Macaw: 7af8ea57aa2cab35b4a52a45e6f85eea753ea9ae
OpenSSL-Universal: 6082b0bf950e5636fe0d78def171184e2b3899c2
RCTDeprecation: a4c521821fab57cbb125b36effe84d897d0dfa12
@@ -2779,7 +2779,7 @@ SPEC CHECKSUMS:
React: e2dc35338068bbd299c66f043ae0d7f25de8499e
React-callinvoker: 28b25d21b124c26cebaea713ba7d801b9351dc48
React-Core: 02ed7d2ffb70437bdf2aba074a13078a7b0b9ff0
- React-Core-prebuilt: b87f4cdecb2229f7d0943644cef9a084d433983d
+ React-Core-prebuilt: 43e26cf5ff020a09ab026c6f6277ad013fa0044f
React-CoreModules: b3a5a42dadcde3b5d47b325bd912eb2ced89e146
React-cxxreact: fe8f88dda044e5905e99a00f41b7a874c3908716
React-debug: 92944dc4d89f56d640e75498266cbde557a48189
@@ -2849,7 +2849,7 @@ SPEC CHECKSUMS:
ReactAppDependencyProvider: 25c9c516839be2c5e3d3344f95dc7da5f7e63fc2
ReactCodegen: 8538eb1bd61031ede1dadd7d725ee1d42dbdceaa
ReactCommon: 7dfc3250793bf36cf221096ff59e1179e13eef7f
- ReactNativeDependencies: b8c3edb93459c2b4531665273e0e904ab3c12ba2
+ ReactNativeDependencies: 2c0483134df7ac059c1f1c484b4fbf6a40451fb5
RNCAsyncStorage: 2ad919e88b8bc2cd80e8697ce66d04d006743283
RNGestureHandler: 2ff61eac036eaf89f6818bf4ed9c39771a17d134
RNReanimated: f735b1747a7a93bda7ca102c6d37a3cf54b6d5e8
diff --git a/apps/mobile-app/ios/VaultUI/Selection/CredentialProviderView.swift b/apps/mobile-app/ios/VaultUI/Selection/CredentialProviderView.swift
index 8a5039217..af3f350bc 100644
--- a/apps/mobile-app/ios/VaultUI/Selection/CredentialProviderView.swift
+++ b/apps/mobile-app/ios/VaultUI/Selection/CredentialProviderView.swift
@@ -261,13 +261,7 @@ private struct AutofillCredentialCardWithSelection: View {
// copy-on-fill setting enabled (default), put the current
// TOTP code on the clipboard so they can paste it into the
// 2FA field after the autofill completes.
- if credential.hasTotp,
- let secret = credential.totpSecret,
- AutofillSettings.shouldCopyTotpOnFill,
- let code = TotpGenerator.generateCode(secret: secret),
- !code.isEmpty {
- UIPasteboard.general.string = code
- }
+ TotpClipboard.copyCodeIfEnabled(secret: credential.totpSecret)
// Fill both username and password immediately for normal autofill
onSelect(identifier, credential.password ?? "")
diff --git a/apps/mobile-app/ios/VaultUtils/TotpClipboard.swift b/apps/mobile-app/ios/VaultUtils/TotpClipboard.swift
new file mode 100644
index 000000000..96af69d00
--- /dev/null
+++ b/apps/mobile-app/ios/VaultUtils/TotpClipboard.swift
@@ -0,0 +1,19 @@
+import Foundation
+import UIKit
+
+/// Puts a credential's current TOTP code on the clipboard while autofilling, so the user can
+/// paste it into the 2FA field after the fill completes.
+public enum TotpClipboard {
+ /// Copy the current TOTP code for `secret` to the clipboard (only when the user has the
+ /// copy-on-fill setting enabled, which is the default).
+ public static func copyCodeIfEnabled(secret: String?) {
+ guard AutofillSettings.shouldCopyTotpOnFill,
+ let secret = secret, !secret.isEmpty,
+ let code = TotpGenerator.generateCode(secret: secret),
+ !code.isEmpty else {
+ return
+ }
+
+ UIPasteboard.general.string = code
+ }
+}