Skip to content

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

Show passkey specific credential view list on "show more" (#520)

Leendert de Borstac7ea057d40b
diff --git a/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Credential.swift b/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Credential.swift
new file mode 100644
index 000000000..1224a5475
--- /dev/null
+++ b/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Credential.swift
@@ -0,0 +1,165 @@
+import AuthenticationServices
+import SwiftUI
+import VaultStoreKit
+import VaultUI
+import VaultModels
+
+/**
+ * Credential-specific functionality for CredentialProviderViewController
+ * This extension handles all password credential operations
+ */
+extension CredentialProviderViewController: CredentialProviderDelegate {
+
+ // MARK: - CredentialProviderDelegate Implementation
+
+ func setupCredentialView(vaultStore: VaultStore, serviceUrl: String?) throws -> UIViewController {
+ // Create the ViewModel with injected behaviors
+ let viewModel = CredentialProviderViewModel(
+ loader: {
+ return try await self.loadCredentials(vaultStore: vaultStore)
+ },
+ selectionHandler: { identifier, password in
+ self.handleCredentialSelection(identifier: identifier, password: password)
+ },
+ cancelHandler: {
+ self.handleCancel()
+ },
+ serviceUrl: serviceUrl
+ )
+
+ // Set text insertion mode if needed
+ if isChoosingTextToInsert {
+ viewModel.isChoosingTextToInsert = true
+ }
+
+ let hostingController = UIHostingController(
+ rootView: CredentialProviderView(viewModel: viewModel)
+ )
+
+ return hostingController
+ }
+
+ func handleCredentialSelection(identifier: String, password: String) {
+ if isChoosingTextToInsert {
+ // For text insertion, insert only the selected text
+ if #available(iOS 18.0, *) {
+ self.extensionContext.completeRequest(
+ withTextToInsert: identifier,
+ completionHandler: nil
+ )
+ } else {
+ // Fallback on earlier versions: do nothing as this feature
+ // is not supported and we should not reach this point?
+ }
+ } else {
+ // For regular credential selection
+ let passwordCredential = ASPasswordCredential(
+ user: identifier,
+ password: password
+ )
+ self.extensionContext.completeRequest(withSelectedCredential: passwordCredential, completionHandler: nil)
+ }
+ }
+
+ func loadCredentials(vaultStore: VaultStore) async throws -> [Credential] {
+ // getAllCredentials now includes passkeys for each credential
+ let credentials = try vaultStore.getAllCredentials()
+
+ // Register all credential identities (passwords and passkeys)
+ await self.registerCredentialIdentities(credentials: credentials)
+
+ return credentials
+ }
+
+ // MARK: - Credential-specific Methods
+
+ override public func prepareInterfaceForUserChoosingTextToInsert() {
+ isChoosingTextToInsert = true
+ // This will be handled by the credential view model when it's created
+ }
+
+ override public func provideCredentialWithoutUserInteraction(for credentialIdentity: ASPasswordCredentialIdentity) {
+ // QuickType bar suggestions are disabled on iOS <26, so this should only be called on iOS 26+
+ if #unavailable(iOS 26.0) {
+ // iOS < 26 - we do not support quick autofill due to buggy behavior
+ print("provideCredentialWithoutUserInteraction called on iOS <26 (unexpected)")
+ self.extensionContext.cancelRequest(
+ withError: NSError(
+ domain: ASExtensionErrorDomain,
+ code: ASExtensionError.userInteractionRequired.rawValue
+ )
+ )
+ return
+ }
+
+ do {
+ let vaultStore = VaultStore()
+
+ // Check if vault database exists
+ guard vaultStore.hasEncryptedDatabase else {
+ self.extensionContext.cancelRequest(
+ withError: NSError(
+ domain: ASExtensionErrorDomain,
+ code: ASExtensionError.userInteractionRequired.rawValue
+ )
+ )
+ return
+ }
+
+ // Unlock vault with biometrics (iOS 26+ works reliably)
+ try vaultStore.unlockVault()
+
+ let credentials = try vaultStore.getAllCredentials()
+
+ if let matchingCredential = credentials.first(where: { credential in
+ return credential.id.uuidString == credentialIdentity.recordIdentifier
+ }) {
+ // Use the identifier that matches the credential identity
+ let identifier = credentialIdentity.user
+ let passwordCredential = ASPasswordCredential(
+ user: identifier,
+ password: matchingCredential.password?.value ?? ""
+ )
+ self.extensionContext.completeRequest(withSelectedCredential: passwordCredential, completionHandler: nil)
+ } else {
+ self.extensionContext.cancelRequest(
+ withError: NSError(
+ domain: ASExtensionErrorDomain,
+ code: ASExtensionError.credentialIdentityNotFound.rawValue
+ )
+ )
+ }
+ } catch {
+ print("provideCredentialWithoutUserInteraction error: \(error)")
+ // On any error, request user interaction
+ self.extensionContext.cancelRequest(
+ withError: NSError(
+ domain: ASExtensionErrorDomain,
+ code: ASExtensionError.userInteractionRequired.rawValue
+ )
+ )
+ }
+ }
+
+ /// Register credential identities for QuickType suggestions
+ private func registerCredentialIdentities(credentials: [Credential]) async {
+ do {
+ if #available(iOS 26.0, *) {
+ // iOS 26+: Register both passwords and passkeys for QuickType and manual selection
+ try await CredentialIdentityStore.shared.saveCredentialIdentities(credentials)
+ print("Registered credential identities (passwords + passkeys) for QuickType on iOS 26+")
+ } else {
+ // iOS 17-25: Only register passkeys (skip passwords for QuickType to avoid biometric issues)
+ // But passkeys MUST be registered so iOS knows to offer this extension for passkey authentication
+ let passkeyOnlyCredentials = credentials.filter { credential in
+ guard let passkeys = credential.passkeys else { return false }
+ return !passkeys.isEmpty
+ }
+ try await CredentialIdentityStore.shared.saveCredentialIdentities(passkeyOnlyCredentials, passkeyOnly: true)
+ print("Registered \(passkeyOnlyCredentials.count) passkey identities on iOS <26 (password QuickType disabled)")
+ }
+ } catch {
+ print("Failed to save credential identities: \(error)")
+ }
+ }
+}
diff --git a/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Passkey.swift b/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Passkey.swift
index a86abe295..a3014db9f 100644
--- a/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Passkey.swift
+++ b/apps/mobile-app/ios/Autofill/CredentialProviderViewController+Passkey.swift
@@ -8,7 +8,103 @@ import VaultModels
* Passkey-related functionality for CredentialProviderViewController
* This extension handles all passkey registration and authentication operations
*/
-extension CredentialProviderViewController {
+extension CredentialProviderViewController: PasskeyProviderDelegate {
+
+ // MARK: - PasskeyProviderDelegate Implementation
+
+ func setupPasskeyView(vaultStore: VaultStore, rpId: String?, clientDataHash: Data?) throws -> UIViewController {
+ let viewModel = PasskeyProviderViewModel(
+ loader: {
+ return try await self.loadPasskeyCredentials(vaultStore: vaultStore, rpId: rpId)
+ },
+ selectionHandler: { credential in
+ if let clientDataHash = clientDataHash, let rpId = rpId {
+ self.handlePasskeyCredentialSelection(credential: credential, clientDataHash: clientDataHash, rpId: rpId)
+ }
+ },
+ cancelHandler: {
+ self.handleCancel()
+ },
+ rpId: rpId
+ )
+
+ let passkeyView = PasskeyProviderView(viewModel: viewModel)
+ let hostingController = UIHostingController(rootView: passkeyView)
+
+ return hostingController
+ }
+
+ func handlePasskeySelection(credential: Credential, clientDataHash: Data, rpId: String) {
+ handlePasskeyCredentialSelection(credential: credential, clientDataHash: clientDataHash, rpId: rpId)
+ }
+
+ func loadPasskeyCredentials(vaultStore: VaultStore, rpId: String?) async throws -> [Credential] {
+ return try await loadPasskeyCredentials(vaultStore: vaultStore, rpId: rpId ?? "")
+ }
+
+ /**
+ * Provide passkey credential without user interaction
+ */
+ internal func providePasskeyCredentialWithoutUserInteraction(for request: ASPasskeyCredentialRequest) {
+ do {
+ let vaultStore = VaultStore()
+
+ // Check vault state
+ guard sanityChecks(vaultStore: vaultStore) else {
+ return
+ }
+
+ // Unlock vault
+ try vaultStore.unlockVault()
+
+ let clientDataHash = request.clientDataHash
+ let credentialIdentity = request.credentialIdentity as? ASPasskeyCredentialIdentity
+ let rpId = credentialIdentity?.relyingPartyIdentifier ?? ""
+ let credentialID = credentialIdentity?.credentialID ?? Data()
+
+ // Look up passkey by credential ID
+ guard let passkey = try vaultStore.getPasskey(byCredentialId: credentialID) else {
+ extensionContext.cancelRequest(withError: NSError(
+ domain: ASExtensionErrorDomain,
+ code: ASExtensionError.credentialIdentityNotFound.rawValue
+ ))
+ return
+ }
+
+ // Generate assertion
+ let credentialId = try? PasskeyHelper.guidToBytes(passkey.id.uuidString)
+ let assertion = try PasskeyAuthenticator.getAssertion(
+ credentialId: credentialId ?? Data(),
+ clientDataHash: clientDataHash,
+ rpId: rpId,
+ privateKeyJWK: passkey.privateKey,
+ userId: passkey.userHandle,
+ uvPerformed: true,
+ prfInputs: nil,
+ prfSecret: passkey.prfKey
+ )
+
+ // Complete the request
+ let credential = ASPasskeyAssertionCredential(
+ userHandle: assertion.userHandle ?? Data(),
+ relyingParty: rpId,
+ signature: assertion.signature,
+ clientDataHash: clientDataHash,
+ authenticatorData: assertion.authenticatorData,
+ credentialID: assertion.credentialId
+ )
+
+ extensionContext.completeAssertionRequest(using: credential)
+
+ } catch {
+ print("Passkey authentication without UI error: \(error)")
+ // Require user interaction if we can't authenticate silently
+ extensionContext.cancelRequest(withError: NSError(
+ domain: ASExtensionErrorDomain,
+ code: ASExtensionError.userInteractionRequired.rawValue
+ ))
+ }
+ }
// MARK: - Passkey Registration
@@ -124,7 +220,7 @@ extension CredentialProviderViewController {
let hostingController = UIHostingController(rootView: passkeyView)
// Remove existing passkey hosting controller if present
- if let existingController = self.passkeyHostingController {
+ if let existingController = self.currentHostingController {
existingController.willMove(toParent: nil)
existingController.view.removeFromSuperview()
existingController.removeFromParent()
@@ -143,7 +239,7 @@ extension CredentialProviderViewController {
])
hostingController.didMove(toParent: self)
- self.passkeyHostingController = hostingController
+ self.currentHostingController = hostingController
}
/**
@@ -313,7 +409,7 @@ extension CredentialProviderViewController {
private func authenticateWithPasskey(_ passkey: Passkey, clientDataHash: Data, rpId: String) throws {
// Generate assertion using PasskeyAuthenticator
let credentialId = try? PasskeyHelper.guidToBytes(passkey.id.uuidString)
-
+
let assertion = try PasskeyAuthenticator.getAssertion(
credentialId: credentialId ?? Data(),
clientDataHash: clientDataHash,
@@ -361,7 +457,7 @@ extension CredentialProviderViewController {
let hostingController = UIHostingController(rootView: passkeyView)
// Remove existing passkey hosting controller if present
- if let existingController = self.passkeyHostingController {
+ if let existingController = self.currentHostingController {
existingController.willMove(toParent: nil)
existingController.view.removeFromSuperview()
existingController.removeFromParent()
@@ -380,15 +476,22 @@ extension CredentialProviderViewController {
])
hostingController.didMove(toParent: self)
- self.passkeyHostingController = hostingController
+ self.currentHostingController = hostingController
}
/**
* Load credentials with passkeys for the specified RP ID
*/
- private func loadPasskeyCredentials(vaultStore: VaultStore, rpId: String) async throws -> [Credential] {
+ internal func loadPasskeyCredentials(vaultStore: VaultStore, rpId: String) async throws -> [Credential] {
// getAllCredentials now includes passkeys for each credential
- let credentials = try vaultStore.getAllCredentials()
+ // TODO: call a separate method for only retrieving passkeys?
+ var credentials = try vaultStore.getAllCredentials()
+
+ // Filter to only include credentials that actually have passkeys
+ credentials = credentials.filter { credential in
+ guard let passkeys = credential.passkeys else { return false }
+ return !passkeys.isEmpty
+ }
// Filter by RP ID if specified
if !rpId.isEmpty {
@@ -423,7 +526,7 @@ extension CredentialProviderViewController {
/**
* Handle passkey credential selection from picker
*/
- private func handlePasskeyCredentialSelection(credential: Credential, clientDataHash: Data, rpId: String) {
+ internal func handlePasskeyCredentialSelection(credential: Credential, clientDataHash: Data, rpId: String) {
do {
// Get the first matching passkey for the RP ID
guard let passkeys = credential.passkeys,
diff --git a/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swift b/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swift
index 09e2f9fcf..ac5cc8ff5 100644
--- a/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swift
+++ b/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swift
@@ -5,33 +5,75 @@ import VaultStoreKit
import VaultUI
import VaultModels
+// MARK: - Protocols
+
+protocol CredentialProviderDelegate: AnyObject {
+ func setupCredentialView(vaultStore: VaultStore, serviceUrl: String?) throws -> UIViewController
+ func handleCredentialSelection(identifier: String, password: String)
+ func loadCredentials(vaultStore: VaultStore) async throws -> [Credential]
+}
+
+protocol PasskeyProviderDelegate: AnyObject {
+ func setupPasskeyView(vaultStore: VaultStore, rpId: String?, clientDataHash: Data?) throws -> UIViewController
+ func handlePasskeySelection(credential: Credential, clientDataHash: Data, rpId: String)
+ func loadPasskeyCredentials(vaultStore: VaultStore, rpId: String?) async throws -> [Credential]
+}
+
/**
- * This class is the main entry point for the autofill extension.
- * It is responsible for displaying the credential provider view and handling user interactions.
- *
- * It also contains interface implementations for ASCredentialProviderViewController that allow
- * us to provide credentials to native system operations that request credentials (e.g. suggesting
- * logins in the keyboard).
+ * Base class for credential provider view controller.
+ * Contains shared functionality and delegates specific behavior to extensions.
*/
public class CredentialProviderViewController: ASCredentialProviderViewController {
- internal var hostingController: UIHostingController<CredentialProviderView>?
- internal var passkeyHostingController: UIViewController?
+ // MARK: - Properties
+ internal var currentHostingController: UIViewController?
internal var isPasskeyRegistrationMode = false
internal var isPasskeyAuthenticationMode = false
- private var viewModel: CredentialProviderViewModel?
- private var isChoosingTextToInsert = false
+ internal var isChoosingTextToInsert = false
private var initialServiceUrl: String?
+ private var currentPasskeyRequest: ASPasskeyCredentialRequest?
+
+ // Delegates for specific credential types
+ weak var credentialDelegate: CredentialProviderDelegate?
+ weak var passkeyDelegate: PasskeyProviderDelegate?
+
+ // MARK: - Initialization
+
+ public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
+ super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
+ setupDelegates()
+ }
+
+ public required init?(coder: NSCoder) {
+ super.init(coder: coder)
+ setupDelegates()
+ }
+
+ private func setupDelegates() {
+ // Set self as delegate for both credential types
+ self.credentialDelegate = self
+ self.passkeyDelegate = self
+ }
override public func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
- // Don't set up credential view if we're in passkey registration or authentication mode
- // These modes are handled by prepareInterface(forPasskeyRegistration:) and
- // prepareInterfaceToProvideCredential(for:) respectively
- if isPasskeyRegistrationMode || isPasskeyAuthenticationMode {
+ print("CredentialProviderViewController: viewWillAppear called - isPasskeyRegistrationMode=\(isPasskeyRegistrationMode), isPasskeyAuthenticationMode=\(isPasskeyAuthenticationMode), domain=\(initialServiceUrl ?? "nil")")
+
+ // Don't set up credential view if we're in passkey registration mode
+ if isPasskeyRegistrationMode {
return
}
+ // If passkey authentication mode is set (from prepareCredentialList detecting passkeys),
+ // show the passkey picker instead of the normal credential list
+ if isPasskeyAuthenticationMode {
+ // If we have a full passkey request (from prepareInterfaceToProvideCredential), use it
+ if let passkeyRequest = currentPasskeyRequest {
+ // This already handled in prepareInterfaceToProvideCredential, just return
+ return
+ }
+ }
+
// Check if there is a stored vault. If not, it means the user has not logged in yet and we
// should redirect to the main app login screen automatically.
let vaultStore = VaultStore()
@@ -56,7 +98,7 @@ public class CredentialProviderViewController: ASCredentialProviderViewControlle
}
// Only set up the view if we haven't already
- if hostingController == nil {
+ if currentHostingController == nil {
do {
try setupView(vaultStore: vaultStore)
} catch {
@@ -80,25 +122,21 @@ public class CredentialProviderViewController: ASCredentialProviderViewControlle
}
private func setupView(vaultStore: VaultStore) throws {
- // Create the ViewModel with injected behaviors
- let viewModel = CredentialProviderViewModel(
- loader: {
- return try await self.loadCredentials(vaultStore: vaultStore)
- },
- selectionHandler: { identifier, password in
- self.handleCredentialSelection(identifier: identifier, password: password)
- },
- cancelHandler: {
- self.handleCancel()
- },
- serviceUrl: initialServiceUrl
- )
-
- self.viewModel = viewModel
-
- let hostingController = UIHostingController(
- rootView: CredentialProviderView(viewModel: viewModel)
- )
+ let hostingController: UIViewController
+
+ if isPasskeyAuthenticationMode {
+ // Use passkey delegate to setup passkey view
+ guard let passkeyDelegate = passkeyDelegate else {
+ throw NSError(domain: "CredentialProviderViewController", code: -1, userInfo: [NSLocalizedDescriptionKey: "Passkey delegate not set"])
+ }
+ hostingController = try passkeyDelegate.setupPasskeyView(vaultStore: vaultStore, rpId: initialServiceUrl, clientDataHash: nil)
+ } else {
+ // Use credential delegate to setup credential view
+ guard let credentialDelegate = credentialDelegate else {
+ throw NSError(domain: "CredentialProviderViewController", code: -1, userInfo: [NSLocalizedDescriptionKey: "Credential delegate not set"])
+ }
+ hostingController = try credentialDelegate.setupCredentialView(vaultStore: vaultStore, serviceUrl: initialServiceUrl)
+ }
addChild(hostingController)
view.addSubview(hostingController.view)
@@ -112,109 +150,38 @@ public class CredentialProviderViewController: ASCredentialProviderViewControlle
])
hostingController.didMove(toParent: self)
- self.hostingController = hostingController
+ self.currentHostingController = hostingController
}
- override public func prepareCredentialList(for serviceIdentifiers: [ASCredentialServiceIdentifier]) {
- let matchedDomains = serviceIdentifiers.map { $0.identifier.lowercased() }
- if let firstDomain = matchedDomains.first {
- initialServiceUrl = firstDomain
-
- // Set the search text to the first domain which will auto filter the credentials
- // to show the most likely credentials first as suggestion.
- viewModel?.setSearchFilter(firstDomain)
+ override public func prepareCredentialList(for: [ASCredentialServiceIdentifier], requestParameters: ASPasskeyCredentialRequestParameters) {
+ print("CredentialProviderViewController: prepareCredentialList called for passkey")
- // Set the service URL to the first domain which will be used to pass onto the
- // add credential view when the user taps the "+" button and prefill it with the
- // domain name.
- viewModel?.serviceUrl = firstDomain
- }
+ self.isPasskeyAuthenticationMode = true
}
- override public func prepareInterfaceForUserChoosingTextToInsert() {
- isChoosingTextToInsert = true
- viewModel?.isChoosingTextToInsert = true
- }
-
- override public func provideCredentialWithoutUserInteraction(for credentialIdentity: ASPasswordCredentialIdentity) {
- // QuickType bar suggestions are disabled on iOS <26, so this should only be called on iOS 26+
- if #unavailable(iOS 26.0) {
- // iOS < 26 - we do not support quick autofill due to buggy behavior
- print("provideCredentialWithoutUserInteraction called on iOS <26 (unexpected)")
- self.extensionContext.cancelRequest(
- withError: NSError(
- domain: ASExtensionErrorDomain,
- code: ASExtensionError.userInteractionRequired.rawValue
- )
- )
- return
- }
-
- do {
- let vaultStore = VaultStore()
-
- // Check if vault database exists
- guard vaultStore.hasEncryptedDatabase else {
- self.extensionContext.cancelRequest(
- withError: NSError(
- domain: ASExtensionErrorDomain,
- code: ASExtensionError.userInteractionRequired.rawValue
- )
- )
- return
- }
-
- // Unlock vault with biometrics (iOS 26+ works reliably)
- try vaultStore.unlockVault()
+ override public func prepareCredentialList(for serviceIdentifiers: [ASCredentialServiceIdentifier]) {
+ print("CredentialProviderViewController: prepareCredentialList called with \(serviceIdentifiers.count) identifiers")
- let credentials = try vaultStore.getAllCredentials()
+ let matchedDomains = serviceIdentifiers.map { $0.identifier.lowercased() }
+ if let firstDomain = matchedDomains.first {
+ print("CredentialProviderViewController: First domain: \(firstDomain)")
- if let matchingCredential = credentials.first(where: { credential in
- return credential.id.uuidString == credentialIdentity.recordIdentifier
- }) {
- // Use the identifier that matches the credential identity
- let identifier = credentialIdentity.user
- let passwordCredential = ASPasswordCredential(
- user: identifier,
- password: matchingCredential.password?.value ?? ""
- )
- self.extensionContext.completeRequest(withSelectedCredential: passwordCredential, completionHandler: nil)
- } else {
- self.extensionContext.cancelRequest(
- withError: NSError(
- domain: ASExtensionErrorDomain,
- code: ASExtensionError.credentialIdentityNotFound.rawValue
- )
- )
- }
- } catch {
- print("provideCredentialWithoutUserInteraction error: \(error)")
- // On any error, request user interaction
- self.extensionContext.cancelRequest(
- withError: NSError(
- domain: ASExtensionErrorDomain,
- code: ASExtensionError.userInteractionRequired.rawValue
- )
- )
+ initialServiceUrl = firstDomain
+ // Delegate will handle the rest of the setup
}
}
- // MARK: - Passkey Support
+ // MARK: - Shared Methods
- override public func prepareInterface(forPasskeyRegistration registrationRequest: ASCredentialRequest) {
- handlePasskeyRegistration(registrationRequest)
+ /// Handle autofill view cancel action.
+ internal func handleCancel() {
+ self.extensionContext.cancelRequest(withError: NSError(
+ domain: ASExtensionErrorDomain,
+ code: ASExtensionError.userCanceled.rawValue
+ ))
}
- override public func prepareInterfaceToProvideCredential(for credentialRequest: ASCredentialRequest) {
- // Check if this is a passkey request
- if let passkeyRequest = credentialRequest as? ASPasskeyCredentialRequest {
- handlePasskeyAuthentication(passkeyRequest)
- return
- }
-
- // Otherwise, handle as password credential (existing behavior)
- // The existing prepareCredentialList method will be called by the system
- }
+ // MARK: - Passkey Support
override public func provideCredentialWithoutUserInteraction(for credentialRequest: ASCredentialRequest) {
// Check if this is a passkey request
@@ -223,8 +190,9 @@ public class CredentialProviderViewController: ASCredentialProviderViewControlle
return
}
- // For password credentials, call the legacy method
+ // For password credentials, delegate to credential extension
if let credentialIdentity = credentialRequest.credentialIdentity as? ASPasswordCredentialIdentity {
+ // This should call the credential extension's provideCredentialWithoutUserInteraction method
provideCredentialWithoutUserInteraction(for: credentialIdentity)
return
}
@@ -236,69 +204,6 @@ public class CredentialProviderViewController: ASCredentialProviderViewControlle
))
}
- /**
- * Provide passkey credential without user interaction
- */
- private func providePasskeyCredentialWithoutUserInteraction(for request: ASPasskeyCredentialRequest) {
- do {
- let vaultStore = VaultStore()
-
- // Check vault state
- guard sanityChecks(vaultStore: vaultStore) else {
- return
- }
-
- // Unlock vault
- try vaultStore.unlockVault()
-
- let clientDataHash = request.clientDataHash
- let credentialIdentity = request.credentialIdentity as? ASPasskeyCredentialIdentity
- let rpId = credentialIdentity?.relyingPartyIdentifier ?? ""
- let credentialID = credentialIdentity?.credentialID ?? Data()
-
- // Look up passkey by credential ID
- guard let passkey = try vaultStore.getPasskey(byCredentialId: credentialID) else {
- extensionContext.cancelRequest(withError: NSError(
- domain: ASExtensionErrorDomain,
- code: ASExtensionError.credentialIdentityNotFound.rawValue
- ))
- return
- }
-
- // Generate assertion
- let credentialId = try? PasskeyHelper.guidToBytes(passkey.id.uuidString)
- let assertion = try PasskeyAuthenticator.getAssertion(
- credentialId: credentialId ?? Data(),
- clientDataHash: clientDataHash,
- rpId: rpId,
- privateKeyJWK: passkey.privateKey,
- userId: passkey.userHandle,
- uvPerformed: true,
- prfInputs: nil,
- prfSecret: passkey.prfKey
- )
-
- // Complete the request
- let credential = ASPasskeyAssertionCredential(
- userHandle: assertion.userHandle ?? Data(),
- relyingParty: rpId,
- signature: assertion.signature,
- clientDataHash: clientDataHash,
- authenticatorData: assertion.authenticatorData,
- credentialID: assertion.credentialId
- )
-
- extensionContext.completeAssertionRequest(using: credential)
-
- } catch {
- print("Passkey authentication without UI error: \(error)")
- // Require user interaction if we can't authenticate silently
- extensionContext.cancelRequest(withError: NSError(
- domain: ASExtensionErrorDomain,
- code: ASExtensionError.userInteractionRequired.rawValue
- ))
- }
- }
/// This registers all known AliasVault credentials (both passwords and passkeys) into iOS native credential storage,
/// which iOS can then use to suggest autofill credentials when a user focuses an input field on a login form.
@@ -406,46 +311,4 @@ public class CredentialProviderViewController: ASCredentialProviderViewControlle
return true
}
- /// Load credentials from the vault store and register them as credential identities
- /// (including both passwords and passkeys) and then return them to the caller (view model).
- private func loadCredentials(vaultStore: VaultStore) async throws -> [Credential] {
- // getAllCredentials now includes passkeys for each credential
- let credentials = try vaultStore.getAllCredentials()
-
- // Register all credential identities (passwords and passkeys)
- await self.registerCredentialIdentities(credentials: credentials)
-
- return credentials
- }
-
- /// Handle autofill view credential selection.
- private func handleCredentialSelection(identifier: String, password: String) {
- if isChoosingTextToInsert {
- // For text insertion, insert only the selected text
- if #available(iOS 18.0, *) {
- self.extensionContext.completeRequest(
- withTextToInsert: identifier,
- completionHandler: nil
- )
- } else {
- // Fallback on earlier versions: do nothing as this feature
- // is not supported and we should not reach this point?
- }
- } else {
- // For regular credential selection
- let passwordCredential = ASPasswordCredential(
- user: identifier,
- password: password
- )
- self.extensionContext.completeRequest(withSelectedCredential: passwordCredential, completionHandler: nil)
- }
- }
-
- /// Handle autofill view cancel action.
- internal func handleCancel() {
- self.extensionContext.cancelRequest(withError: NSError(
- domain: ASExtensionErrorDomain,
- code: ASExtensionError.userCanceled.rawValue
- ))
- }
}