Platform

Sign Up With Apple

15min

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 complete this tutorial, you will need:

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.

2 - Add the Sign In with Apple capability to your XCode project

In your XCode Project, click on the Target (1) and go to the Signing & Capabilities tab (2). Click the + Capability button (3) and add the Sign In with Apple capability (4). While there, choose your Bundle Identifier (5) and hold that information because we will need it later.

Document image


3 - Create a new Service ID

Log into your Apple Developer account and go to the Identifiers section. Check if your created Bundle Identifier is there

Document image


Click the Bundle Identifier and scroll down. Check if the Sign In with Apple is selected

Document image


Click Edit and make sure the Enable as a primary App ID is selected

Document image


If everything is right, save and exit.

4 - Set up Parse Auth for Apple

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

The Apple Login section looks like this:

Document image


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

Document image


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

5 - Option 1 - Download our Template

There is some coding involved in making Sign in With Apple work, so we created this template that you can download, and change the Bundle Identifier, the App Id, and Client Key.

The code is fully documented so it is a good starting point.

If you prefer to read through this doc, please go on to the next step.

6 - Option 2 - Manually write code

Inside your view, add the AuthenticationServices framework and create the AuthDelegate that will handle the PFUserAuthenticationDelegate:

Swift


7 - Implement your Delegates for the ViewController

Implement the ASAuthorizationControllerDelegate and ASAuthorizationControllerPresentationContextProviding for the ViewController:

Swift


8 - Add the Sign In with Apple button

The ViewDidAppear is a good place for it. If you choose other places, remember to call it just once:

Swift


The appleSignInTapped in the last line must also be defined inside the ViewController class:

Swift


9 - The presentationContextProvider

The presentationContextProvider (ASAuthorizationControllerPresentationContextProviding) will ask for which window should display the Authorization dialog. As we are going to display it in the same window, we must return self.view.window:

Swift


10 - Handling the delegate ASAuthorizationControllerDelegate

There are a few options that we must handle when the delegate is called, so let’s add some code to handle those options distinctly:

Swift


11 - Handling the delegate for didCompleteWithAuthorization

When we successfully authenticate, we can retrieve the authorized information:

Swift


That’s the place where we can also add code for logging in Parse. So right after the do what you want with the data here comment, let’s add:

Swift


And of course, add the Parse framework:

Swift