-
Enhance your Sign in with Apple experience
Learn how you can provide safe and fast authentication in your app using Sign in with Apple. We'll show you how you can upgrade password-based accounts into secure, single-tap login credentials, and explore how you can seamlessly handle changes to user sessions in your app. We'll also help you take advantage of Sign In with Apple across the web and on other platforms.
To get the most out of this session, we recommend having familiarity with Sign In with Apple and REST API. We'd also recommend having a basic understanding of JavaScript.Recursos
Videos relacionados
WWDC22
WWDC20
-
Buscar este video…
-
-
4:03 - Presenting Existing Credentials
// Requesting both Sign in with Apple and password-based accounts. import AuthenticationServices let controller = ASAuthorizationController(authorizationRequests: [ ASAuthorizationAppleIDProvider().createRequest(), ASAuthorizationPasswordProvider().createRequest() ]) controller.delegate = self controller.presentationContextProvider = self if #available(iOS 16.0, *) { controller.performRequests(options: .preferImmediatelyAvailableCredentials) } else { controller.performRequests() } -
5:14 - ASAuthorizationControllerDelegate Implementation
// ASAuthorizationControllerDelegate func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) { switch authorization.credential { case let appleIDCredential as ASAuthorizationAppleIDCredential: // Sign the user in with Apple ID credential. // ... case let passwordCredential as ASPasswordCredential: // Sign the user in with password credential // ... } } func authorizationController(controller: ASAuthorizationController, didCompleteWithError error: Error) { // No credential found. Fall back to login UI. } -
12:00 - Checking Credential State
// Check User Credentials on app launch let appleIDProvider = ASAuthorizationAppleIDProvider() appleIDProvider.getCredentialState(forUserID: "currentUserIdentifier") { (credentialState, error) in switch(credentialState){ case .authorized: // Found valid Apple ID credential case .revoked: // Apple ID credential revoked. Log the user out. case .notFound: // No credential found. Show login UI. case .transferred: // Team is transferred } } -
12:18 - Register for Revocation Notification
// Register for revocation notification let notificationName = ASAuthorizationAppleIDProvider.credentialRevokedNotification NotificationCenter.default.addObserver(self, selector: #selector(signOut(_:)), name: notificationName, object: nil) -
17:55 - Sample HTML and Javascript Implementation
// Embed Sign in with Apple JS <html> <body> <script type="text/javascript" src="https://appleid.cdn-apple.com/appleauth/static/jsapi/appleid/1/en_US/appleid.auth.js"></script> <div id="appleid-signin" data-color="white" data-border="true" data-type="sign in"/> <script type="text/javascript"> AppleID.auth.init({ clientId : '[CLIENT_ID]', scope : '[SCOPES]', redirectURI : '[REDIRECT_URI]', state : '[STATE]', nonce : '[NONCE]', usePopup : true }); </script> </body> </html> -
18:28 - White Sign in with Apple Button
<div id="appleid-signin" data-color="white" data-border="true" data-type="sign in"/> -
18:38 - Black Sign in with Apple Button
<div id="appleid-signin" data-color="black" data-border="true" data-type="sign in"/> -
18:44 - Black Continue with Apple Button
<div id="appleid-signin" data-color="black" data-border="true" data-type="continue"/> -
18:50 - Black Logo Only Button
<div id="appleid-signin" data-color="black" data-border="true" data-mode="logo-only"/> -
19:47 - Sample HTML and Javascript Implementation
// Embed Sign in with Apple JS <html> <body> <script type="text/javascript" src="https://appleid.cdn-apple.com/appleauth/static/jsapi/appleid/1/en_US/appleid.auth.js"></script> <div id="appleid-signin" data-color="white" data-border="true" data-type="sign in"/> <script type="text/javascript"> AppleID.auth.init({ clientId : '[CLIENT_ID]', scope : '[SCOPES]', redirectURI : '[REDIRECT_URI]', state : '[STATE]', nonce : '[NONCE]', usePopup : true }); </script> </body> </html> -
21:11 - Handle DOM Response
// Listen for authorization success. document.addEventListener('AppleIDSignInOnSuccess', (event) => { // Handle successful response. console.log(event.detail.data); }); // Listen for authorization failures. document.addEventListener('AppleIDSignInOnFailure', (event) => { // Handle error. console.log(event.detail.error); });
-