Sign in with Apple Unity Plugin v1.4.4 [Unofficial]

Sign in with Apple Unity Plugin v1.4.4 [Unofficial]
RECOMMENDED: GitHub (v1.4.4):
https://github.com/lupidan/apple-signin-unity

Asset store (v1.4.3):
Sign in with Apple Plugin for Unity | Integration | Unity Asset Store (Pending to release 1.4.4)

Overview

This is a FREE, UNOFFICIAL, MIT licensed, open source plugin, to support Sign In With Apple in iOS, tvOS, macOS and visionOS. The plugin is developed by the community, and it´s not the same one as the official plugin from Unity available in the Asset Store.

The main purpose for this plugin is to expose Apple’s newest feature, Sign in with Apple, to the Unity game engine. The plugin started development as soon as Apple announced the feature and has been around for a while already. Version v1.2.0 was released recently, adding macOS support, that´s why I decided to also post it here as well.

On WWDC19, Apple announced Sign in with Apple, and on top of that, they announced that every iOS/tvOS/macOS Application that used any kind of Third party sign-ins (like Sign in with Facebook, or Sign in with Google), will have to support Sign in with Apple in order to get approved for the App Store, making it mandatory.

The plugin is available on GitHub:

Features

  • Support for iOS/tvOS/macOS/visionOS
  • Supports Sign in with Apple, with customizable scopes (Email and Full name).
  • Supports Get Credential status (Authorized, Revoked and Not Found).
  • Supports Quick login (including iTunes Keychain credentials).
  • Supports adding Sign In with Apple capability to Xcode project programatically in a PostBuild script.
  • Supports listening to Credentials Revoked notifications
  • Supports setting custom Nonce and State for authorization requests when Signing In, and attempting a Quick Login.
  • NSError mapping 1:1 so no details are missing.
  • NSPersonNameComponents support (for ALL different styles).
  • Customizable serialization (uses Unity default serialization, but you can add your own implementation)

Installation options

  • Unity Package Manager, just edit your Packages/manifest.json file.

  • Asset store (link at the begining)

  • OpenUPM

  • Unity package file

6 Likes

Nice work!!

1 Like

v1.3.0 Released

Added

  • Adds support to set the State when making a Login or a Quick Login request to sign in with Apple.
  • Improves deserialization for the data.

Changed

  • Makes the parsed classes internal to force the usage of the interfaces.
  • Minor changes for lower C# compatibility
  • GetAuthorizationErrorCode no longer returns a nullable reference type. If the error can’t be obtained, it returns Unknown instead.
2 Likes

@lupidan this looks really cool, thank you for sharing it. Does the keychain feature mean that if you load the same game where the user already authenticated on a different device with the same itunes account that the user will already be considered authenticated (or that userID will be available) on that device as well?

Hi @James15478
Once you login using Sign In With Apple in device A, when you go and install the app in device B, Quick Login should detect your Apple ID was already used for that app, and allow to login again instead of creating a new account. The result of it will be the same user ID.

1 Like

Thanks @lupidan . I noticed you recommend quick login at every app open. But I haven’t really seen this in other apps, they just open without asking for re-authorization (re-signing in). Do you think those apps just save the credentials locally then?

After a successful login/quick login in a device, you get an Apple User ID.
You should save in in the device for the future, and provide it to GetCredentialState to know the status of the user.
There is a diagram describing the flow in the documentation. Please learn about it:

Thanks @lupidan . I’m experimenting with it now. Just using the sample scene atm. It all worked as expected, except after a few tries of revoking permissions and returning to the app, at one point I am just continuingly authorized (I open the app and the user ID shows). I check on device for “Apps using Apple ID” and my app is no longer there, since I revoked permissions, but still shows as authorized in the Unity app. If I reinstall, it seems the quick login pops up as opposed to the “full” login (where it asks for name etc). Do you know why that might be?

Thanks again for the help and cool tool :slight_smile:

v1.3.0 is now available in the Asset Store!

@James15478

If the Sign in with Apple credentials for your app are not granted or revoked, QuickLogin will fail with an error, which is expected. That’s when you redirect the user to the login screen for a Sign In With Apple scenario

If the Sign in with apple credentials are still valid, QuickLogin will display a screen with just the option to proceed (since they were given in the past for yout app and they are still valid)

Basically, if you don’t see the option to give the name, as well as the email selection option, it’s a QuickLogin scenario, where credentials already given in the past, period.

2 Likes

Hi! I’m developing a sign logic for our project using your plugin with Firebase.
To be able to create and login with Apple on Firebase, their documentation requires that we use “appleIdToken” and “rawNonce”.

I’m assuming “appleIdToken” would be the “appleUserId” used through out your plugin to identify the user, correct?
How can I request the “rawNonce” mentioned in Firebase documentation?

For reference: Authenticate Using Apple and Unity  |  Firebase

The raw nonce is something you need to generate randomly for each request.
The apple ID token is referring to the Identity token.

There is some tentative guide on how to put Firebase and this plugin together here:
https://github.com/lupidan/apple-signin-unity/blob/master/docs/Firebase_NOTES.md

I haven´t been able to test it out, but hopefully it can give some more insight on how to proceed.

Hi @lupidan , Thanks for a great plugin! I’m using Gamesparks (www.gamesparks.com) and they require the authorizationCode everytime i want to retrieve a user account.

https://support.gamesparks.net/support/solutions/articles/1000286545-using-sign-in-with-apple-in-gamesparks
https://docs.gamesparks.com/api-documentation/request-api/authentication/signinwithappleconnectrequest.html

Is it possible to get a new authorizationCode each session? Can you expose such functionality in your plugin?

Thanks,
Kristofer

As far as I know, the authorization code is something that’s only provided to you when requesting access with Apple actively (first login only) which will trigger the authentication window.

After the first login/sign in, and successfuly first login/sign in with Gamesparks, your user should be saved in the device and you should just check if the apple user ID is still valid in order to keep that user logged in, or force a logout. (With the CheckCredentialStatus call)

I made a diagram on how I think it should work, make sure you go through it, and adapt it to the needs of Gamespark:

v1.4.2 Released (only on Github)

It’s been a while since I updated the thread. So here is the missing changelog since 1.3.0.
I plan to update the asset store version at some point, Unity’s publishing tools don’t get along well with the project. In the meantime, you can keep using the unity package manager, or download the unity package manually from the releases page on github.

[1.4.2] - 2020-07-17
Changed

  • Handles empty NSPersonNameComponents sent by Apple when not requesting a name, to be nil natively.
  • Updated MacOSAppleAuthManager.bundle with the updated native code

Removed

  • Removes FixSerializationForFullPersonName and any usage of it when deserializing to avoid NRE

[1.4.1] - 2020-11-28
Added

  • Updates plugin’s main MacOSAppleAuthManager.bundle to support Apple Silicon arm64 architecture

Changed

  • Updates some elements in the dedicated macOS documentation file that were incorrect

[1.4.0] - 2020-10-18
Added

  • Adds static class AppleAuthMacosPostprocessorHelper, so now there should always be an AppleAuth.Editor namespace independent of the current platform.
  • Adds static method to AppleAuthMacosPostprocessorHelper, FixManagerBundleIdentifier is a method to change the plugin’s bundle identifier to a custom one based on the current project’s application identifier. This should avoid CFBundleIdentifier collision errors when uploading to the MacOS App Store.
  • Adds enum value for LoginOptions to not request full name or email, LoginOptions.None.

Changed

  • Updates sample code Postprocessor script to support the new recommended post processing for macOS builds
1 Like

v1.4.2 Released on the Asset Store

1 Like

Hi All i have a doubt. I have installed in the plugin… but it shows the error. Metal Api is needed and it works only ios 14 version.

My ipad wont support metal api and my ipad version is only 10.4…

Is there any way that sign in apple works without metal api… or it works only with metal api…

can any one clarify it…

@lupidan

Thanks for creating this package! It all seems quite straightforward, but i have one problem: i can’t figure out where to find the PayloadDeserializer – i get this error:

The type or namespace name ‘PayloadDeserializer’ could not be found (are you missing a using directive or an assembly reference?)

… so it seems like i’m missing a “using directive”, but i’m having the same as in your example code. And pointers on how i can solve this would be appreciated. Thanks!

@realragnvaldr Namespace should be AppleAuth.Native

using AppleAuth.Native;
2 Likes

IOS build failing with Undefined symbols for architecture arm64

Undefined symbols for architecture arm64:
“_UnitySignInWithApple_Login”, referenced from:
_SignInWithApple_LoginInternal_mF47ED0923886387AC79573DD52A2A75D6D8F1FFD in Assembly-CSharp38.o
_SignInWithApple_UnitySignInWithApple_Login_m5A2EF436C683C71D2D6E034D838FD05FDA6F6D3C in Assembly-CSharp38.o
(maybe you meant: _SignInWithApple_UnitySignInWithApple_Login_m5A2EF436C683C71D2D6E034D838FD05FDA6F6D3C)
“_UnitySignInWithApple_GetCredentialState”, referenced from:
_SignInWithApple_GetCredentialStateInternal_mE7725CD83B2C11D10EC76EB24DC795ADBE20DB27 in Assembly-CSharp38.o
_SignInWithApple_UnitySignInWithApple_GetCredentialState_m2DC81A39E66199A01BC2B1B0CBD3C0EB811137D8 in Assembly-CSharp38.o
(maybe you meant: _SignInWithApple_UnitySignInWithApple_GetCredentialState_m2DC81A39E66199A01BC2B1B0CBD3C0EB811137D8)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Those symbols are from Unity’s official Sign in With Apple package. This package is for a completely different plugin.
Please refer your request to Unity support.