2026-09-19 15:33:23 +02:00
|
|
|
//
|
|
|
|
|
// CredentialProviderViewController.swift
|
2026-09-19 15:37:31 +02:00
|
|
|
// AutoFill
|
2026-09-19 15:33:23 +02:00
|
|
|
//
|
|
|
|
|
// Created by Christophe Vila on 19/09/2026.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import AuthenticationServices
|
2026-09-19 19:08:54 +02:00
|
|
|
import SwiftUI
|
2026-09-20 15:05:19 +02:00
|
|
|
import KeeVaultCore
|
2026-09-19 15:33:23 +02:00
|
|
|
|
2026-09-19 19:08:54 +02:00
|
|
|
final class CredentialProviderViewController: ASCredentialProviderViewController {
|
2026-09-19 15:33:23 +02:00
|
|
|
|
2026-09-19 19:08:54 +02:00
|
|
|
private let session = VaultSession()
|
|
|
|
|
private let bookmarkService = FileBookmarkService()
|
2026-09-20 15:05:19 +02:00
|
|
|
private let keychainStore = KeychainStore(accessGroup: "F2KB6W8N4R.org.antiloop222.keevault")
|
2026-09-19 19:08:54 +02:00
|
|
|
private let biometricService = BiometricAuthService()
|
|
|
|
|
|
2026-09-20 15:05:19 +02:00
|
|
|
// Called when the user selects KeeVault from the QuickType bar.
|
2026-09-19 15:33:23 +02:00
|
|
|
override func prepareCredentialList(for serviceIdentifiers: [ASCredentialServiceIdentifier]) {
|
2026-09-19 19:08:54 +02:00
|
|
|
let ids = serviceIdentifiers.map(\.identifier)
|
|
|
|
|
showUI(serviceIdentifiers: ids)
|
2026-09-19 15:33:23 +02:00
|
|
|
}
|
|
|
|
|
|
2026-09-19 19:08:54 +02:00
|
|
|
private func showUI(serviceIdentifiers: [String]) {
|
|
|
|
|
let rootView = ExtensionRootView(
|
|
|
|
|
session: session,
|
|
|
|
|
serviceIdentifiers: serviceIdentifiers,
|
|
|
|
|
bookmarkService: bookmarkService,
|
|
|
|
|
keychainStore: keychainStore,
|
|
|
|
|
biometricService: biometricService,
|
|
|
|
|
onSelect: { [weak self] (entry: Entry) in
|
|
|
|
|
let credential = ASPasswordCredential(
|
|
|
|
|
user: entry.username,
|
|
|
|
|
password: entry.password.reveal()
|
|
|
|
|
)
|
|
|
|
|
self?.extensionContext.completeRequest(withSelectedCredential: credential, completionHandler: nil)
|
|
|
|
|
},
|
|
|
|
|
onCancel: { [weak self] in
|
|
|
|
|
self?.extensionContext.cancelRequest(withError: ASExtensionError(.userCanceled))
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
let host = UIHostingController(rootView: rootView)
|
|
|
|
|
addChild(host)
|
|
|
|
|
view.addSubview(host.view)
|
|
|
|
|
host.view.frame = view.bounds
|
|
|
|
|
host.view.autoresizingMask = [UIView.AutoresizingMask.flexibleWidth, UIView.AutoresizingMask.flexibleHeight]
|
|
|
|
|
host.didMove(toParent: self)
|
2026-09-19 15:33:23 +02:00
|
|
|
}
|
|
|
|
|
}
|