Skip to main content
Docs

Sign in with Apple

This guide will teach you how to add native Sign in with Apple to your Clerk apps on Apple platforms.

Add your Native Application

Add your iOS application to the Native Applications page in the Clerk dashboard. You will need your iOS app's App ID Prefix and Bundle ID.

Enable Apple as a social connection

  1. In the Clerk Dashboard, navigate to the SSO Connections page.
  2. Select Add connection and select For all users.
  3. In the Choose provider dropdown, select Apple.
  4. Ensure that Enable for sign-up and sign-in is toggled on.

Note

Apple provides a privacy feature called Hide My Email, allowing users to sign in to your app with Apple without disclosing their actual email addresses. Instead, your instance receives an app-specific email address that forwards any emails to the user's real address. To be able to send emails properly to users with hidden addresses, you must configure an additional setting in the Apple Developer portal. See Configure Email Source for Apple Private Relay for more information.

Add the Sign in with Apple capability to your app

Add the Sign in with Apple capability to your app.

Obtain an Apple ID Credential

To authenticate with Apple and Clerk, you need to obtain an Apple ID Credential.

To obtain an Apple ID Credential, you can do one of the following:

Note

You must set the nonce property of the ASAuthorizationAppleIDRequest when requesting an Apple ID Credential in order to authenticate with Clerk.

Build your sign-in flow

Once you have obtained your Apple ID Credential, you can use it to authenticate with Clerk by calling SignIn.authenticateWithIdToken(provider:idToken:) with a provider of .apple and the idToken you have obtained.

The following example uses Apple's built-in SignInWithAppleButton to obtain an Apple ID Credential and calls SignIn.authenticateWithIdToken(provider:idToken:) to authenticate with Clerk.

SignInWithAppleView.swift
import SwiftUI
import Clerk
import AuthenticationServices

struct SignInWithAppleView: View {
  var body: some View {
    // Use Apple's built-in SignInWithAppleButton
    SignInWithAppleButton { request in
      request.requestedScopes = [.email, .fullName]
      request.nonce = UUID().uuidString // Setting the nonce is mandatory
    } onCompletion: { result in
      Task {
        // Access the Apple ID Credential
        guard let credential = try result.get().credential as? ASAuthorizationAppleIDCredential else {
          dump("Unable to get credential of type ASAuthorizationAppleIDCredential")
          return
        }

        // Access the necessary identity token on the Apple ID Credential
        guard let idToken = credential.identityToken.flatMap({ String(data: $0, encoding: .utf8) }) else {
          dump("Unable to get ID token from Apple ID Credential.")
          return
        }

        // Authenticate with Clerk
        let authResult = try await SignIn.authenticateWithIdToken(provider: .apple, idToken: idToken)
      }
    }
  }
}

Feedback

What did you think of this content?

Last updated on