swift – Capacitor with iOS Passkey how you can get registration knowledge

I am implementing Passkey to my Ionic app and I could not discover any plugin on the market so I am constructing my very own plugin. Every thing works until triggering the passkey on the native iOS, however I could not get the registration knowledge from iOS. How can I get the info from the AppDelegate? My code is predicated on the Apple official documentation instance: https://developer.apple.com/documentation/authenticationservices/connecting_to_a_service_with_passkeys.
Within the instance, it wanted the AppDelegate to get the registration knowledge delegate, nonetheless I could not handle to make my Capacitor Plugin to make use of the primary AppDelegate. Because of this, authorizationController doesn’t run after passkey registration. Every thing already works tremendous to get problem from webview and go it to native and set off passkey immediate on the iOS machine, simply could not get the registration end result knowledge.
PasskeyPlugin.swift
@objc(PasskeyPlugin)
public class PasskeyPlugin: CAPPlugin {
personal let implementation = Passkey()
@objc func create(_ name: CAPPluginCall) {
let problem: Knowledge? = name.getString("problem")!.knowledge(utilizing: .utf8)
DispatchQueue.most important.async {
let signInViewController = SignInViewController(problem: problem!)
self.bridge?.viewController?.current(signInViewController, animated: true, completion: nil)
}
name.resolve([
"platform": "iOS Native Passkey",
])
}
}
SignInViewController.swift
class SignInViewController: UIViewController {
var problem: Knowledge!
init(problem: Knowledge) {
self.problem = problem
print(self.problem! as NSData)
tremendous.init(nibName: nil, bundle: nil)
}
override func viewDidAppear(_ animated: Bool) {
tremendous.viewDidAppear(animated)
signInObserver = NotificationCenter.default.addObserver(forName: .UserSignedIn, object: nil, queue: nil) {_ in
self.didFinishSignIn()
}
signInErrorObserver = NotificationCenter.default.addObserver(forName: .ModalSignInSheetCanceled, object: nil, queue: nil) { _ in
self.showSignInForm()
}
guard let window = self.view.window else { fatalError("The view was not within the app's view hierarchy!") }
let userName = "Title"
let accountManager = AccountManager()
accountManager.signUpWith(userName: userName, problem: self.problem, anchor: window)
// I can't use the AppDelegate with errors
// (UIApplication.shared.delegate as? AppDelegate)?.accountManager.signUpWith(userName: userName, problem: self.problem, anchor: window)
}
}
AccountManager.swift
extension NSNotification.Title {
static let UserSignedIn = Notification.Title("UserSignedInNotification")
static let ModalSignInSheetCanceled = Notification.Title("ModalSignInSheetCanceledNotification")
}
class AccountManager: NSObject, ASAuthorizationControllerPresentationContextProviding, ASAuthorizationControllerDelegate {
let area = "com.area.my"
var authenticationAnchor: ASPresentationAnchor?
var isPerformingModalReqest = false
func signUpWith(userName: String, problem: Knowledge, anchor: ASPresentationAnchor) {
self.authenticationAnchor = anchor
if #accessible(iOS 15.0, *) {
let publicKeyCredentialProvider = ASAuthorizationPlatformPublicKeyCredentialProvider(relyingPartyIdentifier: area)
// The userID is the identifier for the person's account.
// Laborious coded for instance functions
let userID = "d0a4bc91-2def-4567-8983-9188a4ca2048".knowledge(utilizing: .utf8)!
let registrationRequest = publicKeyCredentialProvider.createCredentialRegistrationRequest(problem: problem,
title: "Some title", userID: userID)
let authController = ASAuthorizationController(authorizationRequests: [ registrationRequest ] )
authController.delegate = self
authController.presentationContextProvider = self
authController.performRequests()
isPerformingModalReqest = true
} else {
// Fallback on earlier variations
}
}
func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
if #accessible(iOS 14.0, *) {
let logger = Logger()
if #accessible(iOS 15.0, *) {
change authorization.credential {
case let credentialRegistration as ASAuthorizationPlatformPublicKeyCredentialRegistration:
logger.log("A brand new passkey was registered: (credentialRegistration)")
// Confirm the attestationObject and clientDataJSON along with your service.
// The attestationObject comprises the person's new public key to retailer and use for subsequent sign-ins.
// let attestationObject = credentialRegistration.rawAttestationObject
// let clientDataJSON = credentialRegistration.rawClientDataJSON
// After the server verifies the registration and creates the person account, signal within the person with the brand new account.
didFinishSignIn()
case let credentialAssertion as ASAuthorizationPlatformPublicKeyCredentialAssertion:
logger.log("A passkey was used to check in: (credentialAssertion)")
// Confirm the beneath signature and clientDataJSON along with your service for the given userID.
// let signature = credentialAssertion.signature
// let clientDataJSON = credentialAssertion.rawClientDataJSON
// let userID = credentialAssertion.userID
// After the server verifies the assertion, signal within the person.
didFinishSignIn()
case let passwordCredential as ASPasswordCredential:
logger.log("A password was supplied: (passwordCredential)")
// Confirm the userName and password along with your service.
// let userName = passwordCredential.person
// let password = passwordCredential.password
// After the server verifies the userName and password, signal within the person.
didFinishSignIn()
default:
fatalError("Acquired unknown authorization sort.")
}
} else {
// Fallback on earlier variations
}
} else {
// Fallback on earlier variations
}
isPerformingModalReqest = false
}
}
How can I get authorizationController to run after passkey immediate on the native machine? Thanks upfront.
Credit: www.ismmailgsm.com