Skip to main content
Version: 5.11.6

Using 'Sign in With Apple'(Logging in With Apple)

Flow of the Process
  1. Log in with an Apple account using the 'Sign in with Apple' function

    1. Obtain an Apple identity Token

    2. Obtain a BACKND Access token by verifying the Apple identity Token

    3. Log in to the BACKND server using the BACKND Access token

    4. Once you obtain the access token, you can use it to perform a token login. For more information on the token, refer to the relevant documentation.

Caution
  • Sign in with Apple works properly only in iOS 13.0 or later.
    • The function requires macOS 10.14(Mojave) or 10.15(Catalina) and Xcode 11 for iOS 13.0.
    • Also, to use this method in an application under development, you must first enable 'Sign in with Apple' in the Apple Developer Portal.
    • For more information, refer to Support for Apple Sign in.
  • Caution when transferring a game between Apple developer accounts
    When transferring a game to another account from the account you first operated on, the Team ID will be changed, bringing upon changes in the unique values(sku of each user) for when users log in. Due to this, you cannot log in using the previous information. This is due to Apple's policy, and if you wish to provide a stable gaming service, BACKND's paid technical support is necessary. If you wish to proceed with the transfer, please make an inquiry to the community or help@thebackend.io in advance to prevent any inconvenience that may occur when operating your game.

Initial settings

Enable Sign in with Apple in the Apple Developer Portal

Access Apple Developer - Member Center, click Certificates, Identifiers & Profiles, enter the relevant app in Identifiers, and check Sign In with Apple.


AuthorizeFederation

public BackendReturnObject AuthorizeFederation(string federationToken, FederationType type);
public BackendReturnObject AuthorizeFederation(string federationToken, FederationType type, string ect);

Parameters

ValueTypeDescription
federationTokenstringToken value created via each login plugin
federationTypeFederationTypeType of federation.(FederationType.Apple)
ectstring(Optional) The piece of information desired to be saved from the additional information

Description

An attempt is made to sign up or log in using the member information token value of Apple.

For more information on how to use the API, see SignInWithApple.cs - a sample script of a sample project provided by Unity.
You can sign up/sign in at LoginCompletedCallback() of SignInWithApple.cs using the idToken value of userInfo.
The following is the token returned from Apple:

eyJraWQiOiJlWGF1bm1MIiwiYWxnIjoiUlMyNTYifQ.eyJpc3MiOiJodHRwczovL2FwcGxlaWQuYXBwbGUuY29tIiwiYXVkIjoiaW8udGhlYmFja2VuZC5CYXNlVGVzdCIsImV4cCI6MTYzNjUxNTEyOSwiaWF0IjoxNjM2NDI4NzI5LCJzdWIiOiIwMDEwODEuNzA3NTgxYzhkOTVkNDc0YWFkMTY2ZmEzYjljNDMyYzkuMDYwNiIsImNfaGFzaCI6InFLaVNFcDUwS21ray1zTUNaU01WQXciLCJlbWFpbCI6ImdhbWVzQHRoZWJhY2tlbmQuaW8iLCJlbWFpbF92ZXJpZmllZCI6InRydWUiLCJhdXRoX3RpbWUiOjE2MzY0Mjg3MjksIm5vbmNlX3N1cHBvcnRlZCI6dHJ1ZX0.PRXylpN4PeatJb59wmCfnkZ8qgBIrV5QUkd4Q4Zhzvua4iXfEZ6ufiO_eaaZR5rGTFmRUOB7w7gIullecc8qzwQY3zFl7DTK3QgMkwxH-uqUn-oLWFOgm-LgVtLvj5KDg7c7yVG0eOQJNr9A40brgCBIcZN6ULGH3tW4wpzqjlVMVD_EEIF9g2xjGL6ZS7KZIS6URjw8WRW5F8tU_V89lMI0OUVawUZ0HmGFey9u9qQkqgq9stPmXDSFwmpe7ASqD2bfPRjP-G6kVWqR8I00bR4--AXTes1YrmNchBfBphoIqJL2LeWuXYuvz--H-CUnQFfgOsWTmr_ExjqnZzwoxQ

Example of a normal code

    BackendReturnObject bro = Backend.BMember.AuthorizeFederation("idToken", FederationType.Apple, "siwa");

if(bro.IsSuccess())
{
Debug.Log("Login with Apple successful");
//Handled as success
}
else
{
Debug.LogError("Sign In with Apple failed");
//Handled as failure
}

Example of Lupidan open source

The code is GameMenuHandler.cs of [Lupidan]'s(https://github.com/lupidan/apple-signin-unity) example project.
Please note the support and inquiry service for the code of this open source is unavailable because the code is not officially provided by BACKND.

public void SetupAppleData(string appleUserId, ICredential receivedCredential)
{
var appleIdCredential = receivedCredential as IAppleIDCredential;
if(appleIdCredential.IdentityToken != null)
{
var identityToken = Encoding.UTF8.GetString(appleIdCredential.IdentityToken, 0, appleIdCredential.IdentityToken.Length);

Debug.Log("Token: " + identityToken);

var bro = Backend.BMember.AuthorizeFederation(identityToken, FederationType.Apple);
Debug.Log("Login result: " + bro);
}

Return cases

Success cases

When the login is successful
statusCode : 200

When signing up as a new member is successful
statusCode : 201

Error cases

When the account is blocked
statusCode : 403
errorCode : Reason for blocking entered in the console

(Using BACKND Appke Login SDK) When identifier does not match identifier entered in the console statusCode : 401
errorCode BadUnauthorizedException


After building, set in Xcode

1) Build Phases > Add Link Binary With Libraries > Add AuthenticationServices.framework > Change Status into Optional

2) Signing & Capabilities > Add Capabilitiy > Add Sign In with Apple