Last active
January 20, 2023 09:31
-
-
Save Kaival-Patel/2076b5c37ade703406e7f1e5546005d9 to your computer and use it in GitHub Desktop.
Passkeys Demonstration (Signup Process)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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