feat: add CredentialProviderViewController skeleton, strip unused storyboard UI
Replace the Xcode boilerplate in AutoFill/CredentialProviderViewController.swift with real logic: prepareCredentialList(for:) builds ExtensionRootView (added in Task 19) inside a UIHostingController, provideCredentialWithoutUserInteraction(for:) silently unlocks via the shared Keychain token and completes/cancels the request. Strip the storyboard's now-unused static nav-bar/button/actions, keeping the same customClass so the system still instantiates this exact class. Also add AutoFill target membership for MyPass/Services/FileBookmarkService.swift and BiometricAuthService.swift (app-target files, referenced directly by the extension per the plan) via explicit PBXFileReference/PBXBuildFile entries, since Xcode's synchronized-group file system only auto-includes them in the MyPass target by default. Expected build state: exactly one error, "cannot find 'ExtensionRootView' in scope" (reported once per simulator architecture), until Task 19 adds that type. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WYqycDFsynHH9VnnK7LNSf
This commit is contained in:
@@ -6,53 +6,71 @@
|
||||
//
|
||||
|
||||
import AuthenticationServices
|
||||
import SwiftUI
|
||||
import MyPassCore
|
||||
|
||||
class CredentialProviderViewController: ASCredentialProviderViewController {
|
||||
final class CredentialProviderViewController: ASCredentialProviderViewController {
|
||||
|
||||
/*
|
||||
Prepare your UI to list available credentials for the user to choose from. The items in
|
||||
'serviceIdentifiers' describe the service the user is logging in to, so your extension can
|
||||
prioritize the most relevant credentials in the list.
|
||||
*/
|
||||
private let session = VaultSession()
|
||||
private let bookmarkService = FileBookmarkService()
|
||||
private let keychainStore = KeychainStore(accessGroup: "org.antiloop222.mypass")
|
||||
private let biometricService = BiometricAuthService()
|
||||
|
||||
// Called when the user selects MyPass from the QuickType bar.
|
||||
override func prepareCredentialList(for serviceIdentifiers: [ASCredentialServiceIdentifier]) {
|
||||
let ids = serviceIdentifiers.map(\.identifier)
|
||||
showUI(serviceIdentifiers: ids)
|
||||
}
|
||||
|
||||
/*
|
||||
Implement this method if your extension supports showing credentials in the QuickType bar.
|
||||
When the user selects a credential from your app, this method will be called with the
|
||||
ASPasswordCredentialIdentity your app has previously saved to the ASCredentialIdentityStore.
|
||||
Provide the password by completing the extension request with the associated ASPasswordCredential.
|
||||
If using the credential would require showing custom UI for authenticating the user, cancel
|
||||
the request with error code ASExtensionError.userInteractionRequired.
|
||||
|
||||
// Called for inline QuickType suggestion (no UI shown).
|
||||
override func provideCredentialWithoutUserInteraction(for credentialIdentity: ASPasswordCredentialIdentity) {
|
||||
let databaseIsUnlocked = true
|
||||
if (databaseIsUnlocked) {
|
||||
let passwordCredential = ASPasswordCredential(user: "j_appleseed", password: "apple1234")
|
||||
self.extensionContext.completeRequest(withSelectedCredential: passwordCredential, completionHandler: nil)
|
||||
} else {
|
||||
self.extensionContext.cancelRequest(withError: NSError(domain: ASExtensionErrorDomain, code:ASExtensionError.userInteractionRequired.rawValue))
|
||||
Task {
|
||||
do {
|
||||
try await unlockSilently()
|
||||
let all = session.allEntries()
|
||||
if let entry = all.first(where: { $0.id.uuidString == credentialIdentity.recordIdentifier }) {
|
||||
let credential = ASPasswordCredential(user: entry.username, password: entry.password.reveal())
|
||||
self.extensionContext.completeRequest(withSelectedCredential: credential, completionHandler: nil)
|
||||
} else {
|
||||
self.extensionContext.cancelRequest(withError: ASExtensionError(.credentialIdentityNotFound))
|
||||
}
|
||||
} catch {
|
||||
self.extensionContext.cancelRequest(withError: ASExtensionError(.userInteractionRequired))
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
Implement this method if provideCredentialWithoutUserInteraction(for:) can fail with
|
||||
ASExtensionError.userInteractionRequired. In this case, the system may present your extension's
|
||||
UI and call this method. Show appropriate UI for authenticating the user then provide the password
|
||||
by completing the extension request with the associated ASPasswordCredential.
|
||||
|
||||
override func prepareInterfaceToProvideCredential(for credentialIdentity: ASPasswordCredentialIdentity) {
|
||||
}
|
||||
*/
|
||||
|
||||
@IBAction func cancel(_ sender: AnyObject?) {
|
||||
self.extensionContext.cancelRequest(withError: NSError(domain: ASExtensionErrorDomain, code: ASExtensionError.userCanceled.rawValue))
|
||||
private func unlockSilently() async throws {
|
||||
guard session.isLocked else { return }
|
||||
let password = try keychainStore.load(for: "masterPassword")
|
||||
let url = try bookmarkService.resolveURL()
|
||||
defer { bookmarkService.stopAccess(url: url) }
|
||||
try session.unlock(url: url, password: password)
|
||||
}
|
||||
|
||||
@IBAction func passwordSelected(_ sender: AnyObject?) {
|
||||
let passwordCredential = ASPasswordCredential(user: "j_appleseed", password: "apple1234")
|
||||
self.extensionContext.completeRequest(withSelectedCredential: passwordCredential, completionHandler: nil)
|
||||
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)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user