Skip to content

Commit 65cf736

Browse files
committed
Merge branch 'main' into feat/passport-prefab
2 parents 111be79 + 4de2af2 commit 65cf736

26 files changed

+866
-323
lines changed

sample/Assets/Scripts/Passport/Login/LoginScript.cs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,51 +27,52 @@ void Start()
2727
ShowOutput("Passport Instance is null");
2828
}
2929

30-
// Set up button listeners if buttons are assigned
31-
if (DefaultLoginButton != null) DefaultLoginButton.onClick.AddListener(() => Login(DirectLoginMethod.None));
32-
if (GoogleLoginButton != null) GoogleLoginButton.onClick.AddListener(() => Login(DirectLoginMethod.Google));
33-
if (AppleLoginButton != null) AppleLoginButton.onClick.AddListener(() => Login(DirectLoginMethod.Apple));
34-
if (FacebookLoginButton != null) FacebookLoginButton.onClick.AddListener(() => Login(DirectLoginMethod.Facebook));
30+
// Set up button listeners using DirectLoginOptions
31+
if (DefaultLoginButton != null) DefaultLoginButton.onClick.AddListener(() => Login(new DirectLoginOptions()));
32+
if (GoogleLoginButton != null) GoogleLoginButton.onClick.AddListener(() => Login(new DirectLoginOptions(DirectLoginMethod.Google)));
33+
if (AppleLoginButton != null) AppleLoginButton.onClick.AddListener(() => Login(new DirectLoginOptions(DirectLoginMethod.Apple)));
34+
if (FacebookLoginButton != null) FacebookLoginButton.onClick.AddListener(() => Login(new DirectLoginOptions(DirectLoginMethod.Facebook)));
3535
}
3636

3737
/// <summary>
3838
/// Logs into Passport using the default auth method.
3939
/// </summary>
4040
public async void Login()
4141
{
42-
await LoginAsync(DirectLoginMethod.None);
42+
await LoginAsync(new DirectLoginOptions());
4343
}
4444

4545
/// <summary>
46-
/// Logs into Passport using the specified direct login method.
46+
/// Logs into Passport using the specified direct login options.
4747
/// </summary>
48-
/// <param name="directLoginMethod">The direct login method to use (Google, Apple, Facebook, or None for default)</param>
49-
public async void Login(DirectLoginMethod directLoginMethod)
48+
/// <param name="directLoginOptions">The direct login options</param>
49+
public async void Login(DirectLoginOptions directLoginOptions)
5050
{
51-
await LoginAsync(directLoginMethod);
51+
await LoginAsync(directLoginOptions);
5252
}
5353

5454
/// <summary>
5555
/// Internal async method that performs the actual login logic.
5656
/// </summary>
57-
/// <param name="directLoginMethod">The direct login method to use</param>
58-
private async System.Threading.Tasks.Task LoginAsync(DirectLoginMethod directLoginMethod)
57+
/// <param name="directLoginOptions">The direct login options</param>
58+
private async System.Threading.Tasks.Task LoginAsync(DirectLoginOptions directLoginOptions)
5959
{
6060
try
6161
{
62-
string methodName = directLoginMethod == DirectLoginMethod.None ? "default" : directLoginMethod.ToString();
63-
ShowOutput($"Logging in with {methodName} method...");
62+
string directLoginMethod = directLoginOptions.directLoginMethod.ToString().ToLower();
6463

65-
bool success = await Passport.Login(useCachedSession: false, directLoginMethod: directLoginMethod);
64+
ShowOutput($"Logging in with {directLoginMethod} method...");
65+
66+
bool success = await Passport.Login(useCachedSession: false, directLoginOptions: directLoginOptions);
6667

6768
if (success)
6869
{
69-
ShowOutput($"Successfully logged in with {methodName}");
70+
ShowOutput($"Successfully logged in with {directLoginMethod}");
7071
SceneManager.LoadScene("AuthenticatedScene");
7172
}
7273
else
7374
{
74-
ShowOutput($"Failed to log in with {methodName}");
75+
ShowOutput($"Failed to log in with {directLoginMethod}");
7576
}
7677
}
7778
catch (OperationCanceledException ex)

src/Packages/Marketplace/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "com.immutable.marketplace",
3-
"version": "1.36.1",
3+
"version": "1.36.4",
44
"description": "Marketplace package for the Immutable SDK for Unity",
55
"displayName": "Immutable Marketplace",
66
"author": {

src/Packages/Passport/Runtime/Resources/index.html

Lines changed: 25 additions & 25 deletions
Large diffs are not rendered by default.

src/Packages/Passport/Runtime/Scripts/Private/Helpers/SdkVersionInfoHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ public class SdkVersionInfoHelpers
44
{
55
public static string GetSdkVersionInfo()
66
{
7-
return "1.36.1";
7+
return "1.36.4";
88
}
99
}
1010
}

src/Packages/Passport/Runtime/Scripts/Private/Helpers/WindowsDeepLink.cs

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
using System;
33
using System.IO;
44
using System.Runtime.InteropServices;
5+
using System.Diagnostics;
6+
#if UNITY_EDITOR
7+
using UnityEditor;
8+
#endif
59
using UnityEditor;
610
using UnityEngine;
711
using Immutable.Passport.Core.Logging;
@@ -179,7 +183,7 @@ private static void CreateCommandScript(string protocolName)
179183
// Store deeplink URI in registry
180184
$"REG ADD \"HKCU\\Software\\Classes\\{protocolName}\" /v \"{REGISTRY_DEEP_LINK_NAME}\" /t REG_SZ /d %1 /f >nul 2>&1",
181185
// Check if game is already running
182-
$"tasklist /FI \"IMAGENAME eq {gameExeName}\" 2>NUL | find /I \"{gameExeName}\" >NUL",
186+
$"tasklist /FI \"IMAGENAME eq {gameExeName}\" >nul 2>&1",
183187
"if %ERRORLEVEL%==0 (",
184188
// Bring existing game window to foreground
185189
" powershell -NoProfile -ExecutionPolicy Bypass -Command ^",
@@ -271,11 +275,45 @@ private static void RegisterProtocol(string protocolName)
271275
RegCloseKey(commandKey);
272276
RegCloseKey(hKey);
273277
}
274-
278+
275279
private static string GetGameExecutablePath(string suffix)
276280
{
277-
var exeName = Application.productName + suffix;
278-
return Path.Combine(Application.persistentDataPath, exeName).Replace("/", "\\");
281+
#if !UNITY_EDITOR_WIN
282+
if (suffix == ".exe")
283+
{
284+
// Get the path of the currently running executable
285+
try
286+
{
287+
var process = System.Diagnostics.Process.GetCurrentProcess();
288+
if (process?.MainModule?.FileName != null)
289+
{
290+
return process.MainModule.FileName.Replace("/", "\\");
291+
}
292+
}
293+
catch (System.ComponentModel.Win32Exception ex)
294+
{
295+
PassportLogger.Warn($"Failed to get process MainModule: {ex.Message}. Using fallback method.");
296+
}
297+
catch (System.InvalidOperationException ex)
298+
{
299+
PassportLogger.Warn($"Process inaccessible: {ex.Message}. Using fallback method.");
300+
}
301+
302+
// Fallback: Use command line args
303+
var args = System.Environment.GetCommandLineArgs();
304+
if (args.Length > 0 && !string.IsNullOrEmpty(args[0]))
305+
{
306+
var exePath = Path.GetFullPath(args[0]);
307+
if (File.Exists(exePath))
308+
{
309+
return exePath.Replace("/", "\\");
310+
}
311+
}
312+
}
313+
#endif
314+
// For the editor, or for .cmd files in a build, use persistentDataPath as it's a writable location
315+
var fileName = Application.productName + suffix;
316+
return Path.Combine(Application.persistentDataPath, fileName).Replace("/", "\\");
279317
}
280318

281319
private void OnApplicationFocus(bool hasFocus)

src/Packages/Passport/Runtime/Scripts/Private/Model/DirectLoginMethod.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
namespace Immutable.Passport.Model
44
{
55
/// <summary>
6-
/// Enum for direct login methods supported by Passport.
6+
/// Enum representing direct login methods for authentication providers.
77
/// </summary>
88
[Serializable]
99
public enum DirectLoginMethod
1010
{
11-
None,
11+
Email,
1212
Google,
1313
Apple,
1414
Facebook
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System;
2+
3+
namespace Immutable.Passport.Model
4+
{
5+
/// <summary>
6+
/// Structure representing direct login options for authentication.
7+
/// Can be used for social login (google, apple, facebook) or email login.
8+
/// </summary>
9+
[Serializable]
10+
public class DirectLoginOptions
11+
{
12+
/// <summary>
13+
/// Authentication method.
14+
/// </summary>
15+
public DirectLoginMethod directLoginMethod = DirectLoginMethod.Email;
16+
17+
/// <summary>
18+
/// Email address for email-based authentication (only used when directLoginMethod is Email).
19+
/// </summary>
20+
public string email;
21+
22+
/// <summary>
23+
/// Default constructor.
24+
/// </summary>
25+
public DirectLoginOptions()
26+
{
27+
directLoginMethod = DirectLoginMethod.Email;
28+
email = null;
29+
}
30+
31+
/// <summary>
32+
/// Constructor with method and email.
33+
/// </summary>
34+
/// <param name="loginMethod">The direct login method</param>
35+
/// <param name="emailAddress">The email address (optional)</param>
36+
public DirectLoginOptions(DirectLoginMethod loginMethod, string emailAddress = null)
37+
{
38+
directLoginMethod = loginMethod;
39+
email = emailAddress;
40+
}
41+
42+
/// <summary>
43+
/// Checks if the email is valid and should be included in requests.
44+
/// </summary>
45+
/// <returns>True if email is valid for email method</returns>
46+
public bool IsEmailValid()
47+
{
48+
return directLoginMethod == DirectLoginMethod.Email && !string.IsNullOrEmpty(email);
49+
}
50+
}
51+
}

src/Packages/Passport/Runtime/Scripts/Private/Model/DirectLoginOptions.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Packages/Passport/Runtime/Scripts/Private/Model/Request/GetPKCEAuthUrlRequest.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ internal class GetPKCEAuthUrlRequest
1414
public bool isConnectImx;
1515

1616
/// <summary>
17-
/// The direct login method to use for authentication.
17+
/// The direct login options for authentication.
1818
/// </summary>
19-
public string directLoginMethod;
19+
public DirectLoginOptions directLoginOptions;
2020

2121
/// <summary>
22-
/// Creates a new GetPKCEAuthUrlRequest.
22+
/// Creates a new GetPKCEAuthUrlRequest with DirectLoginOptions.
2323
/// </summary>
2424
/// <param name="isConnectImx">Whether this is a connect to IMX operation</param>
25-
/// <param name="directLoginMethod">The direct login method to use</param>
26-
public GetPKCEAuthUrlRequest(bool isConnectImx, DirectLoginMethod directLoginMethod)
25+
/// <param name="directLoginOptions">The direct login options to use</param>
26+
public GetPKCEAuthUrlRequest(bool isConnectImx, DirectLoginOptions directLoginOptions)
2727
{
2828
this.isConnectImx = isConnectImx;
29-
this.directLoginMethod = directLoginMethod == DirectLoginMethod.None ? null : directLoginMethod.ToString().ToLower();
29+
this.directLoginOptions = directLoginOptions;
3030
}
3131
}
3232
}

src/Packages/Passport/Runtime/Scripts/Private/PassportImpl.cs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class PassportImpl
2525
private readonly PassportAnalytics _analytics = new();
2626

2727
private bool _pkceLoginOnly; // Used to differentiate between a login and connect
28-
private DirectLoginMethod _directLoginMethod; // Store the direct login method for current operation
28+
private DirectLoginOptions _directLoginOptions; // Store the direct login options for current operation
2929
private UniTaskCompletionSource<bool>? _pkceCompletionSource;
3030
private string _redirectUri;
3131
private string _logoutRedirectUri;
@@ -98,7 +98,7 @@ public void SetCallTimeout(int ms)
9898
_communicationsManager.SetCallTimeout(ms);
9999
}
100100

101-
public UniTask<bool> Login(bool useCachedSession = false, DirectLoginMethod directLoginMethod = DirectLoginMethod.None)
101+
public UniTask<bool> Login(bool useCachedSession = false, DirectLoginOptions directLoginOptions = null)
102102
{
103103
if (useCachedSession)
104104
{
@@ -113,7 +113,7 @@ public UniTask<bool> Login(bool useCachedSession = false, DirectLoginMethod dire
113113
var task = new UniTaskCompletionSource<bool>();
114114
_pkceCompletionSource = task;
115115
_pkceLoginOnly = true;
116-
_directLoginMethod = directLoginMethod;
116+
_directLoginOptions = directLoginOptions;
117117
#if UNITY_STANDALONE_WIN || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN)
118118
WindowsDeepLink.Initialise(_redirectUri, OnDeepLinkActivated);
119119
#endif
@@ -163,7 +163,7 @@ private async UniTask<bool> Relogin()
163163
return false;
164164
}
165165

166-
public async UniTask<bool> ConnectImx(bool useCachedSession = false, DirectLoginMethod directLoginMethod = DirectLoginMethod.None)
166+
public async UniTask<bool> ConnectImx(bool useCachedSession = false, DirectLoginOptions directLoginOptions = null)
167167
{
168168
if (useCachedSession)
169169
{
@@ -189,7 +189,7 @@ public async UniTask<bool> ConnectImx(bool useCachedSession = false, DirectLogin
189189
UniTaskCompletionSource<bool> task = new UniTaskCompletionSource<bool>();
190190
_pkceCompletionSource = task;
191191
_pkceLoginOnly = false;
192-
_directLoginMethod = directLoginMethod;
192+
_directLoginOptions = directLoginOptions;
193193

194194
#if UNITY_STANDALONE_WIN || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN)
195195
WindowsDeepLink.Initialise(_redirectUri, OnDeepLinkActivated);
@@ -275,8 +275,24 @@ private async UniTask LaunchAuthUrl()
275275
{
276276
try
277277
{
278-
var request = new GetPKCEAuthUrlRequest(!_pkceLoginOnly, _directLoginMethod);
279-
var callResponse = await _communicationsManager.Call(PassportFunction.GET_PKCE_AUTH_URL, JsonUtility.ToJson(request));
278+
// Create the request JSON manually to ensure proper serialization
279+
var requestJson = $"{{\"isConnectImx\":{(!_pkceLoginOnly).ToString().ToLower()}";
280+
281+
if (_directLoginOptions != null)
282+
{
283+
requestJson += $",\"directLoginOptions\":{{\"directLoginMethod\":\"{_directLoginOptions.directLoginMethod.ToString().ToLower()}\"";
284+
285+
if (_directLoginOptions.IsEmailValid())
286+
{
287+
requestJson += $",\"email\":\"{_directLoginOptions.email}\"";
288+
}
289+
290+
requestJson += "}";
291+
}
292+
293+
requestJson += "}";
294+
295+
var callResponse = await _communicationsManager.Call(PassportFunction.GET_PKCE_AUTH_URL, requestJson);
280296
var response = callResponse.OptDeserializeObject<StringResponse>();
281297

282298
if (response != null && response.success == true && response.result != null)

0 commit comments

Comments
 (0)