Apple SignIn with Firebase

Sign in with Apple was announced in 2019 and allows users to authenticate into your Firebase app with an Apple ID. Users must have two-factor authentication (2FA) enabled on their Apple account AND be signed into iCloud.

The following lesson demonstrates how to configure Apple SignIn with the Firebase JavaScript SDK.

Sign in with Apple Setup

Follow the steps outlined below to implement Sign In with Apple in your app.

Step 0 - Apple Developer Program

You must be a member of the Apple Developer Program. It costs $99 per year.

Step 1 - Create or Update an App ID

From the Apple Developer Portal go to Certificates, Identifiers & Profiles » Identifiers. Create a new App ID or update an existing app and give it the Sign In with Apple capability.

Apple Developer Portal App IDs
Make sure Sign In with Apple is Enabled

Make sure Sign In with Apple is Enabled

Step 2 - Create and Configure a Service ID

From Certificates, Identifiers & Profiles » Identifiers, create a new Service ID and make sure is linked to your primary App ID. Configure it point to your Firebase hosting URL.

Replace the project ID for your domain

Replace the project ID for your domain

Step 3 - Verify Domain Ownership

Go to Service ID you created in the previous step and click configure, then click download. Save the file in your web app’s public hosting directory under ./well-known/.

Deploy this file to your domain so Apple can verify it.

command line
firebase deploy --only hosting

You should see a green checkmark next to the domain

You should see a green checkmark next to the domain

Step 4 - Register a Private Key

From Certificates, Identifiers & Profiles » Identifiers, create and download a new private key - keep it private. It is used to validate requests from Apple with your Firebase project.

Download the private key. Do not expose it publicly.

Download the private key. Do not expose it publicly.

Step 5 - Enable SignIn Method on Firebase

Head over the to the Firebase Console and go to the Authentication » Sign-in Method tab. Enable Apple and enter the required details.

Copy the contents of the private key in the console

Copy the contents of the private key in the console

Frontend Code

We now have all the pieces in place to implement SignIn with Apple into our web app. Because this is Firebase, it only requires a few lines of code. Assuming you have Firebase installed in your project, simply make a reference the the provider and call signInWithPopup().

SignIn with Apple popup seen by the end-user

SignIn with Apple popup seen by the end-user

Basic JavaScript Implementation

The frontend implementation is an async function that can bound to a button click to trigger the popup modal. Make sure to follow Apple UI guidelines when designing the button.

file_type_js_official app.js
const auth = firebase.auth();

async signInWithApple() {
    const provider = new firebase.auth.OAuthProvider('apple.com');
    const result = await auth.signInWithPopup(provider);

    console.log(result.user); // logged-in Apple user
}

Q&A Chat