Skip to content

Login with Apple

Privy supports native Apple login on iOS. Apple is an OAuth2.0 compliant authentication provider, but requires a specific implementation of Apple sign-in within iOS apps.

TIP

Prior to integrating Sign in with Apple, make sure your app's Bundle ID rather than the Service ID, is configured as the Client ID within the Privy Dashboard.

The "Sign in with Apple" button

Apple's Human Interface Guidelines has a clear definition of how the Sign in with Apple button should look. In order to ensure compliance with Apple's guidelines, we recommend you use the ASAuthorizationAppleIDButton class from Apple's AuthenticationServices framework.

Take a look at the snippet below if you wish to use the ASAuthorizationAppleIDButton in SwiftUI.

swift
struct SignInWithApple: UIViewRepresentable {
  typealias UIViewType = ASAuthorizationAppleIDButton
  func makeUIView(context: Context) -> ASAuthorizationAppleIDButton {
    return ASAuthorizationAppleIDButton()
  }

  func updateUIView(_ uiView: ASAuthorizationAppleIDButton, context: Context) {
  }
}

WARNING

Apple's AuthenticationServices framework also offers the SignInWithAppleButton SwiftUI View, but relying on ASAuthorizationAppleIDButton instead allows the PrivySDK to handle the whole authentication process for you.

Initializing Apple login

Privy automatically implements and launches Apple's native ASAuthorizationController after calling privy.oAuth.login(with: OAuthProvider.apple). Add the SignInWithApple button to your view as described above, and trigger the login method when tapped.

swift
// Add the SignInWithApple button with your view and register the tap gesture
SignInWithApple()
    .onTapGesture {
        // Ideally this is called in a view model, but showcasing logic here for brevity
        Task {
            do {
                // The `appUrlScheme` param is not necessary for using Sign in with Apple.
                // Privy will use the first valid app URL scheme from your app's info.plist.
                // Ensure your client's url schemes are registered in the Privy dashboard
                let authSession = try await privy.oAuth.login(with: OAuthProvider.apple)
            } catch {
                debugPrint("Error: \(error)")
                // Handle errors
            }
        }
    }