Skip to content

Commit

Permalink
Merge pull request #76 from lupidan/canary
Browse files Browse the repository at this point in the history
  • Loading branch information
lupidan authored Oct 18, 2020
2 parents 38da711 + 1168f4d commit 17e3149
Show file tree
Hide file tree
Showing 13 changed files with 145 additions and 36 deletions.
2 changes: 1 addition & 1 deletion AppleAuth/AppleAuthManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class AppleAuthManager : IAppleAuthManager
{
static AppleAuthManager()
{
const string versionMessage = "Using Sign in with Apple Unity Plugin - v1.3.0";
const string versionMessage = "Using Sign in with Apple Unity Plugin - v1.4.0";
#if APPLE_AUTH_MANAGER_NATIVE_IMPLEMENTATION_AVAILABLE
PInvoke.AppleAuth_LogMessage(versionMessage);
#else
Expand Down
47 changes: 47 additions & 0 deletions AppleAuth/Editor/AppleAuthMacosPostprocessorHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.IO;
using System.Text.RegularExpressions;
using UnityEditor;
using UnityEngine;

namespace AppleAuth.Editor
{
public static class AppleAuthMacosPostprocessorHelper
{
/// <summary>
/// Use this script to change the bundle identifier of the plugin's library bundle to replace it with a personalized one for your product.
/// This should avoid CFBundleIdentifier Collision errors when uploading the app to the macOS App Store
/// </summary>
/// <remarks>Basically this should replace the plugin's bundle identifier from "com.lupidan.MacOSAppleAuthManager" to "{your.project.application.identifier}.MacOSAppleAuthManager"</remarks>
/// <param name="target">The current build target, so it's only executed when building for MacOS</param>
/// <param name="path">The path of the built .app file</param>
public static void FixManagerBundleIdentifier(BuildTarget target, string path)
{
if (target != BuildTarget.StandaloneOSX)
{
Debug.LogError("AppleAuthMacosPostprocessorHelper: FixManagerBundleIdentifier should only be called when building for macOS");
return;
}

const string bundleIdentifierPattern = @"(\<key\>CFBundleIdentifier\<\/key\>\s*\<string\>)(com\.lupidan)(\.MacOSAppleAuthManager\<\/string\>)";
const string macOSAppleAuthManagerInfoPlistRelativePath = "/Contents/Plugins/MacOSAppleAuthManager.bundle/Contents/Info.plist";

try
{
var macosAppleAuthManagerInfoPlistPath = path + macOSAppleAuthManagerInfoPlistRelativePath;
var macosAppleAuthManagerInfoPlist = File.ReadAllText(macosAppleAuthManagerInfoPlistPath);
var modifiedMacosAppleAuthManagerInfoPlist = Regex.Replace(
macosAppleAuthManagerInfoPlist,
bundleIdentifierPattern,
"$1" + PlayerSettings.applicationIdentifier + "$3");

File.WriteAllText(macosAppleAuthManagerInfoPlistPath, modifiedMacosAppleAuthManagerInfoPlist);
Debug.Log("AppleAuthMacosPostprocessorHelper: Renamed MacOSAppleAuthManager.bundle bundle identifier from \"com.lupidan.MacOSAppleAuthManager\" -> \"" + PlayerSettings.applicationIdentifier + ".MacOSAppleAuthManager\"");
}
catch (Exception exception)
{
Debug.LogError("AppleAuthMacosPostprocessorHelper: Error while fixing MacOSAppleAuthManager.bundle bundle identifier :: " + exception.Message);
}
}
}
}
3 changes: 3 additions & 0 deletions AppleAuth/Editor/AppleAuthMacosPostprocessorHelper.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions AppleAuth/Enums/LoginOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ namespace AppleAuth.Enums
[Flags]
public enum LoginOptions
{
/// <summary>
/// Empty scope. No full name or email
/// </summary>
None = 0,

/// <summary>
/// A scope that includes the user’s full name.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>19G73</string>
<string>19H2</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
Expand All @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.3.0</string>
<string>1.4.0</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>MacOSX</string>
Expand All @@ -27,17 +27,19 @@
<key>DTCompiler</key>
<string>com.apple.compilers.llvm.clang.1_0</string>
<key>DTPlatformBuild</key>
<string>11E608c</string>
<string>12A7300</string>
<key>DTPlatformName</key>
<string>macosx</string>
<key>DTPlatformVersion</key>
<string>GM</string>
<string>10.15.6</string>
<key>DTSDKBuild</key>
<string>19E258</string>
<string>19G68</string>
<key>DTSDKName</key>
<string>macosx10.15</string>
<key>DTXcode</key>
<string>1150</string>
<string>1201</string>
<key>DTXcodeBuild</key>
<string>11E608c</string>
<string>12A7300</string>
<key>LSMinimumSystemVersion</key>
<string>10.9</string>
<key>NSHumanReadableCopyright</key>
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion AppleAuth/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.lupidan.apple-signin-unity-src",
"displayName": "Sign in with Apple [Local Source]",
"version": "1.3.0",
"version": "1.4.0",
"unity": "2018.3",
"description": "[Local Source]\nProvides a Unity bridge to use the native Sign In With Apple method on iOS/iPadOS/tvOS/macOS devices",
"author": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#if UNITY_IOS || UNITY_TVOS
#define UNITY_XCODE_EXTENSIONS_AVAILABLE
#endif

using AppleAuth.Editor;
using UnityEditor;
using UnityEditor.Callbacks;
#if UNITY_XCODE_EXTENSIONS_AVAILABLE
using UnityEditor.iOS.Xcode;
#endif

namespace AppleAuthSample.Editor
{
Expand All @@ -14,23 +18,27 @@ public static class SignInWithApplePostprocessor
[PostProcessBuild(CallOrder)]
public static void OnPostProcessBuild(BuildTarget target, string path)
{
if (target != BuildTarget.iOS && target != BuildTarget.tvOS)
return;

var projectPath = PBXProject.GetPBXProjectPath(path);
#if UNITY_2019_3_OR_NEWER
var project = new PBXProject();
project.ReadFromString(System.IO.File.ReadAllText(projectPath));
var manager = new ProjectCapabilityManager(projectPath, "Entitlements.entitlements", null, project.GetUnityMainTargetGuid());
manager.AddSignInWithAppleWithCompatibility(project.GetUnityFrameworkTargetGuid());
manager.WriteToFile();
#else
var manager = new ProjectCapabilityManager(projectPath, "Entitlements.entitlements", PBXProject.GetUnityTargetName());
manager.AddSignInWithAppleWithCompatibility();
manager.WriteToFile();
#endif
if (target == BuildTarget.iOS || target == BuildTarget.tvOS)
{
#if UNITY_XCODE_EXTENSIONS_AVAILABLE
var projectPath = PBXProject.GetPBXProjectPath(path);
#if UNITY_2019_3_OR_NEWER
var project = new PBXProject();
project.ReadFromString(System.IO.File.ReadAllText(projectPath));
var manager = new ProjectCapabilityManager(projectPath, "Entitlements.entitlements", null, project.GetUnityMainTargetGuid());
manager.AddSignInWithAppleWithCompatibility(project.GetUnityFrameworkTargetGuid());
manager.WriteToFile();
#else
var manager = new ProjectCapabilityManager(projectPath, "Entitlements.entitlements", PBXProject.GetUnityTargetName());
manager.AddSignInWithAppleWithCompatibility();
manager.WriteToFile();
#endif
#endif
}
else if (target == BuildTarget.StandaloneOSX)
{
AppleAuthMacosPostprocessorHelper.FixManagerBundleIdentifier(target, path);
}
}
}
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ PlayerSettings:
16:10: 1
16:9: 1
Others: 1
bundleVersion: 1.3.0
bundleVersion: 1.4.0
preloadedAssets: []
metroInputSource: 0
wsaTransparentSwapchain: 0
Expand Down
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## [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.3.0] - 2020-07-18
### Added
- Adds support to set the `State` when making a Login or a Quick Login request to sign in with Apple.
Expand Down Expand Up @@ -77,7 +86,8 @@
- Added support to listen to Revoked Credentials notifications
- Solved possible crashes that could happen when trying to execute a callback in the Native Message Handler, if the callback was to throw an exception, the application would crash.

[Unreleased]: https://github.com/lupidan/apple-signin-unity/compare/v1.3.0...HEAD
[Unreleased]: https://github.com/lupidan/apple-signin-unity/compare/v1.4.0...HEAD
[1.4.0]: https://github.com/lupidan/apple-signin-unity/compare/v1.3.0...v1.4.0
[1.3.0]: https://github.com/lupidan/apple-signin-unity/compare/v1.2.0...v1.3.0
[1.2.0]: https://github.com/lupidan/apple-signin-unity/compare/v1.1.0...v1.2.0
[1.1.0]: https://github.com/lupidan/apple-signin-unity/compare/v1.0.0...v1.1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@
INFOPLIST_FILE = MacOSAppleAuthManager/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Bundles";
MACOSX_DEPLOYMENT_TARGET = 10.9;
MARKETING_VERSION = 1.3.0;
MARKETING_VERSION = 1.4.0;
ONLY_ACTIVE_ARCH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.lupidan.MacOSAppleAuthManager;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -307,7 +307,7 @@
INFOPLIST_FILE = MacOSAppleAuthManager/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Bundles";
MACOSX_DEPLOYMENT_TARGET = 10.9;
MARKETING_VERSION = 1.3.0;
MARKETING_VERSION = 1.4.0;
PRODUCT_BUNDLE_IDENTIFIER = com.lupidan.MacOSAppleAuthManager;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
Expand Down
44 changes: 39 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ by **Daniel Lupiañez Casares**
+ [Why do I need to call Update manually on the AppleAuthManager instance?](#why-do-i-need-to-call-update-manually-on-the-appleAuthManager-instance)
+ [What deserialization library does it use by default?](#what-deserialization-library-does-it-use-by-default)
+ [Any way to get a refresh token after the first user authorization?](#any-way-to-get-a-refresh-token-after-the-first-user-authorization)
+ [I am getting a CFBundleIdentifier Collision error when uploading my app to the macOS App Store](#i-am-getting-a-cfbundleIdentifier-collision-error-when-uploading-my-app-to-the-macos-app-store)

## Overview
Sign in with Apple plugin to use with Unity 3D game engine.
Expand Down Expand Up @@ -95,7 +96,7 @@ Sign in with Apple in order to get approved for the App Store, making it **manda

## Installation

> Current stable version is v1.3.0
> Current stable version is v1.4.0
There are two options available to install this plugin. Either using the Unity Package Manager, or the traditional `.unitypackage` file.

Expand All @@ -109,7 +110,7 @@ Just add this line to the `Packages/manifest.json` file of your Unity Project:

```json
"dependencies": {
"com.lupidan.apple-signin-unity": "https://github.com/lupidan/apple-signin-unity.git#v1.3.0",
"com.lupidan.apple-signin-unity": "https://github.com/lupidan/apple-signin-unity.git#v1.4.0",
}
```

Expand Down Expand Up @@ -217,10 +218,32 @@ The provided extension method uses reflection to integrate with the current tool
## Plugin setup (macOS)

An unsigned precompiled `.bundle` file is available. It will be automatically included in your macOS builds.
However that `.bundle` needs to be modified to avoid issues when uploading it to the MacOS App Store.

In particular, the bundle identifier of that `.bundle` needs to be modified to a custom one.

To automate the process, there is a helper method that will change the bundle identifier to one based on your project's application identifier.
You should call this method on a Postprocess build script of your choice.

```csharp
using AppleAuth.Editor;

public static class SignInWithApplePostprocessor
{
[PostProcessBuild(1)]
public static void OnPostProcessBuild(BuildTarget target, string path)
{
if (target != BuildTarget.StandaloneOSX)
return;

AppleAuthMacosPostprocessorHelper.FixManagerBundleIdentifier(target, path);
}
}
```

The Xcode project with the source code to generate a new bundle file is available at `MacOSAppleAuthManager/MacOSAppleAuthManager.xcodeproj`

To support the feature, the app needs to be codesigned correctly, including the required entitlements. For more information regarding macOS codesign, please follow this [link](./docs/macOS_NOTES.md).
To support the feature, **the app needs to be codesigned correctly**, including the required entitlements. For more information regarding macOS codesign, please follow this [link](./docs/macOS_NOTES.md).

## Implement Sign in With Apple

Expand Down Expand Up @@ -462,11 +485,11 @@ If you want to test new account scenarios, you need to [revoke](#how-can-i-logou

### Is it possible to NOT request the user's email or full name?

Yes! By passing `0` to the `LoginWithAppleId` method the user will not be asked for their email or full name.
Yes, just provide `LoginOptions.None` when calling `LoginWithAppleId` and the user will not be asked for their email or full name.
This will skip that entire login step and make it more smooth. It is recommended if the user's email or full name is not used.

```csharp
appleAuthManager.LoginWithAppleId(0, credential => {}, error =>{});
appleAuthManager.LoginWithAppleId(LoginOptions.None, credential => { ... }, error => { ... });
```

### Does the plugin use UnitySendMessage?
Expand All @@ -489,3 +512,14 @@ You can also implement your own deserialization by implementing an `IPayloadDese

It seems currently is not possible to do so. You can read more details [here](https://github.com/lupidan/apple-signin-unity/issues/3)

### I am getting a CFBundleIdentifier Collision error when uploading my app to the macOS App Store:

If you are experiencing an error like this when uploading your macOS app to the App Store
> The info.plist CFBundleIdentifier value 'com.lupidan.MacOSAppleAuthManager" of 'appname.app/Contents/Plugins/MacOSAppleAuthManager.bundle' is already in use by another application"
It probably means that your [postprocess build script for macOS](#plugin-setup-macos) is not setup correctly.

You should call `AppleAuthMacosPostprocessorHelper.FixManagerBundleIdentifier` to fix the plugin's bundle identifier to a custom one for your app.

You can find more details about the bug [here](https://github.com/lupidan/apple-signin-unity/issues/72)

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.lupidan.apple-signin-unity",
"displayName": "Sign in with Apple",
"version": "1.3.0",
"version": "1.4.0",
"unity": "2018.3",
"description": "Provides a Unity bridge to use the native Sign In With Apple method on iOS/iPadOS/tvOS/macOS devices",
"author": {
Expand Down

0 comments on commit 17e3149

Please sign in to comment.