Skip to content

Instantly share code, notes, and snippets.

@Kaival-Patel
Last active January 20, 2023 09:31
Show Gist options
  • Select an option

  • Save Kaival-Patel/2076b5c37ade703406e7f1e5546005d9 to your computer and use it in GitHub Desktop.

Select an option

Save Kaival-Patel/2076b5c37ade703406e7f1e5546005d9 to your computer and use it in GitHub Desktop.
Passkeys Demonstration (Signup Process)
import AuthenticationServices
import Foundation
import os
extension NSNotification.Name {
static let UserSignedIn = Notification.Name("UserSignedInNotification")
static let ModalSignInSheetCanceled = Notification.Name("ModalSignInSheetCanceledNotification")
}
class AccountManager: NSObject, ASAuthorizationControllerPresentationContextProviding, ASAuthorizationControllerDelegate {
//To setup backend side, https://quickbirdstudios.com/blog/ios-passkeys/
//Define your connected domain
let domain = "example.com"
var authenticationAnchor: ASPresentationAnchor?
var isPerformingModalReqest = false
//IN THIS CLASS WE WILL WORK WITH SEVERAL METHODS
//SIGN IN METHOD
func signInWith(anchor: ASPresentationAnchor, preferImmediatelyAvailableCredentials: Bool) {
//SIGN IN METHOD IMPLEMENTATION
}
//SIGN UP METHOD
func signUpWith(userName: String, anchor: ASPresentationAnchor) {
//SIGN UP METHOD IMPLEMENTATION
}
func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
///TO HANDLE CALLBACKS ON [REGISTRATION], [SIGN IN], [PROVIDED VIA PASSWORD]
}
func authorizationController(controller: ASAuthorizationController, didCompleteWithError error: Error) {
//TO HANDLE ERROR CALLBACKS
}
//OTHER METHODS
func presentationAnchor(for controller: ASAuthorizationController) -> ASPresentationAnchor {
return authenticationAnchor!
}
func didFinishSignIn() {
NotificationCenter.default.post(name: .UserSignedIn, object: nil)
}
func didCancelModalSheet() {
NotificationCenter.default.post(name: .ModalSignInSheetCanceled, object: nil)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment