Back4App

Sign In with Apple Tutorial

Introduction

Sign In with Apple enables users to sign in to Apps using their Apple ID. This feature is available on iOS 13 and later, and Parse 3.5 and later.

Prerequisites

To begin with this tutorial, you will need:

Step 1 - Create a New Back4App App

First of all, it’s necessary to make sure that you have an existing app created at Back4App. However, if you are a new user, you can check this tutorial to learn how to create one.

Step 2 - Create a new Identifier

Log into your Apple Developer account and go to Certificates, IDs & Profiles

ID

Go to Identifiers and click the + button to add a new App ID

ID

Choose App IDs

ID

Mark Sign In with Apple and click the Edit button on the right

ID

Make sure Enable as a primary App ID is selected

ID

Fill up the Description and use a reverse domain to set the Bundle ID. Click Continue when done.

ID

Check if all the information is right and click Register`

ID

Step 3 - Create a new Service ID

Back to the Identifiers section, click the + button again

ID

This time check Services IDs`

ID

Fill up the Description and the Identifier. The Identifier must be different than the one set in Identifiers, so just add the suffix “id” at the end of it.

Mark Sign In with Apple and click Edit

ID

Choose the correct Primary App ID for your Application and set the Web Domainand the Return URLs. The Web Domain will be the subdomain used in Back4app, which you set in Server Settings > Web Hosting and Live Queries. You can learn how to set up a subdomain in this tutorial. The Return URLs will be the URLs to be redirected after a successful login.

ID

Download the apple-developer-domain-association.txt file.

Step 4 - Verifying your Domain

Create a new file called app.js and paste the following content in it:

1
2
3
4
let path = require("path");
app.get('/.well-known/apple-developer-domain-association.txt', (req, res) => {
    res.sendFile(path.join(__dirname, 'public/well-known/apple-developer-domain-association.txt'));
});

Upload it to your Cloud folder in the Cloud Code Functions section. In your Public folder, create a subfolder named well-known and upload the apple-developer-domain-association.txt in it.

You can now verify your domain in the Apple website. After the verification, save everything.

Step 5 - Create a new Key

Go to the Keys section and click the + button to add a new Key

ID

ID

Fill up the Key Name, check Sign In with Apple and click Configure`

ID

Make sure the Primary App ID is correct and save

ID

At the end download your new Key by clicking the Download button.

ATTENTION: Save this key in a safe place as you will not be able to download it again.

ID

Step 6 - Set up Parse Auth for Apple

Go to Back4App website, log in and then find your app. After that, click on Server Settings and search for the Apple Login block and select Settings.

The Apple Login section looks like this:

ID

Now, you just need to paste your Bundle ID in the field below and click on the button to save.

ID

In case you face any trouble while integrating Apple Login, please contact our team via chat!

Step 7 - Start the development

Now that the Sign In with Apple is configured, you can start the development process.

The Sign In with Apple for iOS is available.

Here is the method for the iOS SDK:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
PFUser.logInWithAuthType(inBackground: "apple", authData: ["token":tokenString, "id": user]).continueWith { task -> Any? in
    if ((task.error) != nil){
        print("ERROR: \(task.error?.localizedDescription)")
    }
    return task
    
    if let userObject = task.result {
        print("LOGGED IN PARSE")
    } else {
        // Failed to log in.
        print("ERROR LOGGING IN IN PARSE: \(task.error?.localizedDescription)")
    }
    return nil
}

And here for the Android SDK:

1
2
3
4
5
6
Map<string, string> authData = new HashMap<string, string>(); 
authData.put("token", tokenString);
authData.put("id", user);
ParseUser.logInWithInBackground("apple", authData){

}