Skip to content

Commit

Permalink
Merge pull request #51 from lupidan/canary
Browse files Browse the repository at this point in the history
v1.3.0 Release
  • Loading branch information
lupidan authored Jul 18, 2020
2 parents e245b10 + 49b2451 commit 8656e71
Show file tree
Hide file tree
Showing 26 changed files with 245 additions and 129 deletions.
5 changes: 4 additions & 1 deletion AppleAuth/AppleAuthLoginArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ public struct AppleAuthLoginArgs
{
public readonly LoginOptions Options;
public readonly string Nonce;
public readonly string State;

public AppleAuthLoginArgs(
LoginOptions options,
string nonce = null)
string nonce = null,
string state = null)
{
this.Options = options;
this.Nonce = nonce;
this.State = state;
}
}
}
23 changes: 19 additions & 4 deletions AppleAuth/AppleAuthManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ namespace AppleAuth
{
public class AppleAuthManager : IAppleAuthManager
{
static AppleAuthManager()
{
const string versionMessage = "Using Sign in with Apple Unity Plugin - v1.3.0";
#if APPLE_AUTH_MANAGER_NATIVE_IMPLEMENTATION_AVAILABLE
PInvoke.AppleAuth_LogMessage(versionMessage);
#else
UnityEngine.Debug.Log(versionMessage);
#endif
}

#if APPLE_AUTH_MANAGER_NATIVE_IMPLEMENTATION_AVAILABLE
private readonly IPayloadDeserializer _payloadDeserializer;

Expand Down Expand Up @@ -47,6 +57,7 @@ public void QuickLogin(
{
#if APPLE_AUTH_MANAGER_NATIVE_IMPLEMENTATION_AVAILABLE
var nonce = quickLoginArgs.Nonce;
var state = quickLoginArgs.State;
var requestId = CallbackHandler.AddMessageCallback(
true,
payload =>
Expand All @@ -60,7 +71,7 @@ public void QuickLogin(
successCallback(response.AppleIDCredential);
});

PInvoke.AppleAuth_QuickLogin(requestId, nonce);
PInvoke.AppleAuth_QuickLogin(requestId, nonce, state);
#else
throw new Exception("AppleAuthManager is not supported in this platform");
#endif
Expand All @@ -79,6 +90,7 @@ public void LoginWithAppleId(
#if APPLE_AUTH_MANAGER_NATIVE_IMPLEMENTATION_AVAILABLE
var loginOptions = loginArgs.Options;
var nonce = loginArgs.Nonce;
var state = loginArgs.State;
var requestId = CallbackHandler.AddMessageCallback(
true,
payload =>
Expand All @@ -90,7 +102,7 @@ public void LoginWithAppleId(
successCallback(response.AppleIDCredential);
});

PInvoke.AppleAuth_LoginWithAppleId(requestId, (int)loginOptions, nonce);
PInvoke.AppleAuth_LoginWithAppleId(requestId, (int)loginOptions, nonce, state);
#else
throw new Exception("AppleAuthManager is not supported in this platform");
#endif
Expand Down Expand Up @@ -310,13 +322,16 @@ public static void NativeMessageHandlerCallback(uint requestId, string payload)
public static extern void AppleAuth_GetCredentialState(uint requestId, string userId);

[System.Runtime.InteropServices.DllImport(DllName)]
public static extern void AppleAuth_LoginWithAppleId(uint requestId, int loginOptions, string nonceCStr);
public static extern void AppleAuth_LoginWithAppleId(uint requestId, int loginOptions, string nonceCStr, string stateCStr);

[System.Runtime.InteropServices.DllImport(DllName)]
public static extern void AppleAuth_QuickLogin(uint requestId, string nonceCStr);
public static extern void AppleAuth_QuickLogin(uint requestId, string nonceCStr, string stateCStr);

[System.Runtime.InteropServices.DllImport(DllName)]
public static extern void AppleAuth_RegisterCredentialsRevokedCallbackId(uint callbackId);

[System.Runtime.InteropServices.DllImport(DllName)]
public static extern void AppleAuth_LogMessage(string messageCStr);
}
#endif
}
Expand Down
4 changes: 3 additions & 1 deletion AppleAuth/AppleAuthQuickLoginArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ namespace AppleAuth
public struct AppleAuthQuickLoginArgs
{
public readonly string Nonce;
public readonly string State;

public AppleAuthQuickLoginArgs(string nonce = null)
public AppleAuthQuickLoginArgs(string nonce = null, string state = null)
{
this.Nonce = nonce;
this.State = state;
}
}
}
7 changes: 6 additions & 1 deletion AppleAuth/Editor/ProjectCapabilityManagerExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ public static void AddSignInWithAppleWithCompatibility(this ProjectCapabilityMan
var mainTargetGuid = targetGuidField.GetValue(manager) as string;
var capabilityType = constructorInfo.Invoke(new object[] { "com.apple.developer.applesignin.custom", true, string.Empty, true }) as PBXCapabilityType;

var targetGuidToAddFramework = unityFrameworkTargetGuid ?? mainTargetGuid;
var targetGuidToAddFramework = unityFrameworkTargetGuid;
if (targetGuidToAddFramework == null)
{
targetGuidToAddFramework = mainTargetGuid;
}

project.AddFrameworkToProject(targetGuidToAddFramework, AuthenticationServicesFramework, true);
project.AddCapability(mainTargetGuid, capabilityType, entitlementFilePath, false);
}
Expand Down
4 changes: 2 additions & 2 deletions AppleAuth/Extensions/AppleErrorExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ namespace AppleAuth.Extensions
{
public static class AppleErrorExtensions
{
public static AuthorizationErrorCode? GetAuthorizationErrorCode(this IAppleError error)
public static AuthorizationErrorCode GetAuthorizationErrorCode(this IAppleError error)
{
if (error.Domain == "com.apple.AuthenticationServices.AuthorizationError" &&
Enum.IsDefined(typeof(AuthorizationErrorCode), error.Code))
{
return (AuthorizationErrorCode)error.Code;
}

return null;
return AuthorizationErrorCode.Unknown;
}
}
}
14 changes: 7 additions & 7 deletions AppleAuth/Native/AppleError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
namespace AppleAuth.Native
{
[Serializable]
public class AppleError : IAppleError, ISerializationCallbackReceiver
internal class AppleError : IAppleError, ISerializationCallbackReceiver
{
public int _code;
public string _domain;
public string _localizedDescription;
public string[] _localizedRecoveryOptions;
public string _localizedRecoverySuggestion;
public string _localizedFailureReason;
public int _code = 0;
public string _domain = null;
public string _localizedDescription = null;
public string[] _localizedRecoveryOptions = null;
public string _localizedRecoverySuggestion = null;
public string _localizedFailureReason = null;

public int Code { get { return this._code; } }
public string Domain { get { return this._domain; } }
Expand Down
38 changes: 22 additions & 16 deletions AppleAuth/Native/AppleIDCredential.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,36 @@
namespace AppleAuth.Native
{
[Serializable]
public class AppleIDCredential : IAppleIDCredential, ISerializationCallbackReceiver
internal class AppleIDCredential : IAppleIDCredential, ISerializationCallbackReceiver
{
public string _identityToken;
public string _authorizationCode;
public string _state;
public string _user;
public string[] _authorizedScopes;
public bool _hasFullName;
public FullPersonName _fullName;
public string _email;
public RealUserStatus _realUserStatus;

public byte[] IdentityToken { get { return Convert.FromBase64String(this._identityToken); } }
public byte[] AuthorizationCode { get { return Convert.FromBase64String(this._authorizationCode); } }
public string _base64IdentityToken = null;
public string _base64AuthorizationCode = null;
public string _state = null;
public string _user = null;
public string[] _authorizedScopes = null;
public bool _hasFullName = false;
public FullPersonName _fullName = null;
public string _email = null;
public int _realUserStatus = 0;

private byte[] _identityToken;
private byte[] _authorizationCode;

public byte[] IdentityToken { get { return this._identityToken; } }
public byte[] AuthorizationCode { get { return this._authorizationCode; } }
public string State { get { return this._state; } }
public string User { get { return this._user; } }
public string[] AuthorizedScopes { get { return this._authorizedScopes; } }
public IPersonName FullName { get { return this._fullName; } }
public string Email { get { return this._email; } }
public RealUserStatus RealUserStatus { get { return this._realUserStatus; } }
public RealUserStatus RealUserStatus { get { return (RealUserStatus) this._realUserStatus; } }

public void OnBeforeSerialize() { }

public void OnAfterDeserialize()
{
SerializationTools.FixSerializationForString(ref this._identityToken);
SerializationTools.FixSerializationForString(ref this._authorizationCode);
SerializationTools.FixSerializationForString(ref this._base64IdentityToken);
SerializationTools.FixSerializationForString(ref this._base64AuthorizationCode);
SerializationTools.FixSerializationForString(ref this._state);
SerializationTools.FixSerializationForString(ref this._user);
SerializationTools.FixSerializationForString(ref this._email);
Expand All @@ -42,6 +45,9 @@ public void OnAfterDeserialize()
SerializationTools.FixSerializationForObject(ref this._fullName, this._hasFullName);

SerializationTools.FixSerializationForFullPersonName(ref this._fullName);

this._identityToken = SerializationTools.GetBytesFromBase64String(this._base64IdentityToken, "_identityToken");
this._authorizationCode = SerializationTools.GetBytesFromBase64String(this._base64AuthorizationCode, "_authorizationCode");
}
}
}
16 changes: 8 additions & 8 deletions AppleAuth/Native/CredentialStateResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
namespace AppleAuth.Native
{
[Serializable]
public class CredentialStateResponse : ICredentialStateResponse, ISerializationCallbackReceiver
internal class CredentialStateResponse : ICredentialStateResponse, ISerializationCallbackReceiver
{
public bool _success;
public bool _hasCredentialState;
public bool _hasError;
public CredentialState _credentialState;
public AppleError _error;
public bool _success = false;
public bool _hasCredentialState = false;
public bool _hasError = false;
public int _credentialState = 0;
public AppleError _error = null;

public bool Success { get { return this._success; } }
public CredentialState CredentialState { get { return this._credentialState; } }
public CredentialState CredentialState { get { return (CredentialState) this._credentialState; } }
public IAppleError Error { get { return this._error; } }

public void OnBeforeSerialize() { }
Expand All @@ -26,4 +26,4 @@ public void OnAfterDeserialize()
SerializationTools.FixSerializationForObject(ref this._error, this._hasError);
}
}
}
}
6 changes: 3 additions & 3 deletions AppleAuth/Native/FullPersonName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
namespace AppleAuth.Native
{
[Serializable]
public class FullPersonName : PersonName, IPersonName
internal class FullPersonName : PersonName, IPersonName
{
public bool _hasPhoneticRepresentation;
public PersonName _phoneticRepresentation;
public bool _hasPhoneticRepresentation = false;
public PersonName _phoneticRepresentation = null;

public new IPersonName PhoneticRepresentation { get { return _phoneticRepresentation; } }

Expand Down
16 changes: 8 additions & 8 deletions AppleAuth/Native/LoginWithAppleIdResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
namespace AppleAuth.Native
{
[Serializable]
public class LoginWithAppleIdResponse : ILoginWithAppleIdResponse, ISerializationCallbackReceiver
internal class LoginWithAppleIdResponse : ILoginWithAppleIdResponse, ISerializationCallbackReceiver
{
public bool _success;
public bool _hasAppleIdCredential;
public bool _hasPasswordCredential;
public bool _hasError;
public AppleIDCredential _appleIdCredential;
public PasswordCredential _passwordCredential;
public AppleError _error;
public bool _success = false;
public bool _hasAppleIdCredential = false;
public bool _hasPasswordCredential = false;
public bool _hasError = false;
public AppleIDCredential _appleIdCredential = null;
public PasswordCredential _passwordCredential = null;
public AppleError _error = null;

public bool Success { get { return this._success; } }
public IAppleError Error { get { return this._error; } }
Expand Down
6 changes: 3 additions & 3 deletions AppleAuth/Native/PasswordCredential.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
namespace AppleAuth.Native
{
[Serializable]
public class PasswordCredential : IPasswordCredential, ISerializationCallbackReceiver
internal class PasswordCredential : IPasswordCredential, ISerializationCallbackReceiver
{
public string _user;
public string _password;
public string _user = null;
public string _password = null;

public string User { get { return this._user; } }
public string Password { get { return this._password; } }
Expand Down
16 changes: 9 additions & 7 deletions AppleAuth/Native/PersonName.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
using System;
using AppleAuth.Interfaces;
using UnityEngine;

namespace AppleAuth.Native
{
public class PersonName : IPersonName, ISerializationCallbackReceiver
[Serializable]
internal class PersonName : IPersonName, ISerializationCallbackReceiver
{
public string _namePrefix;
public string _givenName;
public string _middleName;
public string _familyName;
public string _nameSuffix;
public string _nickname;
public string _namePrefix = null;
public string _givenName = null;
public string _middleName = null;
public string _familyName = null;
public string _nameSuffix = null;
public string _nickname = null;

public string NamePrefix { get { return _namePrefix; } }
public string GivenName { get { return _givenName; } }
Expand Down
26 changes: 25 additions & 1 deletion AppleAuth/Native/SerializationTools.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;

namespace AppleAuth.Native
{
internal static class SerializationTools
Expand Down Expand Up @@ -32,5 +34,27 @@ internal static void FixSerializationForFullPersonName(ref FullPersonName origin
originalFullPersonName = default(FullPersonName);
}
}

internal static byte[] GetBytesFromBase64String(string base64String, string fieldName)
{
if (base64String == null)
{
return null;
}

var returnedBytes = default(byte[]);
try
{
returnedBytes = Convert.FromBase64String(base64String);
}
catch (Exception exception)
{
Console.WriteLine("Received exception while deserializing byte array for " + fieldName);
Console.WriteLine("Exception: " + exception);
returnedBytes = null;
}

return returnedBytes;
}
}
}
}
11 changes: 6 additions & 5 deletions AppleAuth/Native/iOS/AppleAuthManager.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// MIT License
//
// Copyright (c) 2019 Daniel Lupiañez Casares
// Copyright (c) 2019-2020 Daniel Lupiañez Casares
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -37,8 +37,8 @@ typedef void (*NativeMessageHandlerDelegate)(uint requestId, const char* payloa

+ (instancetype) sharedManager;

- (void) quickLogin:(uint)requestId withNonce:(NSString *)nonce;
- (void) loginWithAppleId:(uint)requestId withOptions:(AppleAuthManagerLoginOptions)options andNonce:(NSString *)nonce;
- (void) quickLogin:(uint)requestId withNonce:(NSString *)nonce andState:(NSString *)state;
- (void) loginWithAppleId:(uint)requestId withOptions:(AppleAuthManagerLoginOptions)options nonce:(NSString *)nonce andState:(NSString *)state;
- (void) getCredentialStateForUser:(NSString *)userId withRequestId:(uint)requestId;
- (void) registerCredentialsRevokedCallbackForRequestId:(uint)requestId;

Expand All @@ -47,8 +47,9 @@ typedef void (*NativeMessageHandlerDelegate)(uint requestId, const char* payloa
bool AppleAuth_IsCurrentPlatformSupported(void);
void AppleAuth_SetupNativeMessageHandlerCallback(NativeMessageHandlerDelegate callback);
void AppleAuth_GetCredentialState(uint requestId, const char* userId);
void AppleAuth_LoginWithAppleId(uint requestId, int options, const char* _Nullable nonceCStr);
void AppleAuth_QuickLogin(uint requestId, const char* _Nullable nonceCStr);
void AppleAuth_LoginWithAppleId(uint requestId, int options, const char* _Nullable nonceCStr, const char* _Nullable stateCStr);
void AppleAuth_QuickLogin(uint requestId, const char* _Nullable nonceCStr, const char* _Nullable stateCStr);
void AppleAuth_RegisterCredentialsRevokedCallbackId(uint requestId);
void AppleAuth_LogMessage(const char* _Nullable messageCStr);

NS_ASSUME_NONNULL_END
Loading

0 comments on commit 8656e71

Please sign in to comment.