Docs

Sign in with Apple

Warning

The Clerk iOS SDK is currently in beta. It is not yet recommended for production use.

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

Configure the Apple social connection

To support native Sign in with Apple, you need to configure the Apple social connection in the Clerk Dashboard. To do so, follow the native-specific instructions in the OAuth with Apple guide.

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.create(strategy:) with a strategy of .idToken followed by .authenticateWithIdToken().

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

SignInWithAppleView.swift
import SwiftUI
import ClerkSDK
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
          .create(strategy: .idToken(provider: .apple, idToken: idToken))
          .authenticateWithIdToken()
      }
    }
  }
}

Feedback

What did you think of this content?

Last updated on