Skip to content

Commit e474f9a

Browse files
authored
Merge pull request #481 from immutable/fix/windows-pkce
[ID-3737] fix: windows pkce cmd errors, protocol name, pkce docs
2 parents 6ff003b + 020fdcd commit e474f9a

File tree

7 files changed

+26
-16
lines changed

7 files changed

+26
-16
lines changed

sample/Assets/Scenes/Passport/SelectAuthMethod.unity

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1866,21 +1866,20 @@ MonoBehaviour:
18661866
18671867
18681868
1.
1869-
Authorisation Code Flow with Proof Key for Code Exchange (PKCE) is available
1870-
for Android, iOS, macOS and WebGL (not officially supported). This method provides
1869+
Authorisation Code Flow with Proof Key for Code Exchange (PKCE): This method provides
18711870
a seamless and secure authentication experience by opening a pop-up window on
1872-
macOS or an in-app browser on mobile devices. Players are automatically redirected
1871+
desktop or an in-app browser on mobile devices. Players are automatically redirected
18731872
back to the game once authenticated, eliminating manual switching.
18741873
18751874
18761875
2. Device
1877-
Code Authorisation is available for Windows, Android, iOS and macOS. This method
1876+
Code Authorisation: This method
18781877
opens the player''s default browser and guides them through the authentication
18791878
flow.
18801879
18811880
18821881
Recommendation: Whenever possible, use the PKCE flow as it is the
1883-
most secure and seamless method for authentication on Android, iOS and macOS.'
1882+
most secure and seamless method for authentication.'
18841883
--- !u!222 &1688502351
18851884
CanvasRenderer:
18861885
m_ObjectHideFlags: 0

sample/Assets/Scripts/Passport/PassportInitialisation/PassportInitialisationScript.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public void UsePKCE()
5656
/// <summary>
5757
/// Initialises Passport.
5858
/// </summary>
59-
/// <param name="redirectUri">(Android, iOS and macOS only) The URL to which auth will redirect the browser after
59+
/// <param name="redirectUri">The URL to which auth will redirect the browser after
6060
/// authorisation has been granted by the user</param>
6161
/// <param name="logoutRedirectUri">The URL to which auth will redirect the browser
6262
/// after log out is complete</param>

sample/Assets/Scripts/Passport/_tutorials~/PassportInitialisation/tutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ For PKCE authentication, the redirect URIs must be configured correctly based on
7575
### Prerequisites
7676
- Create an Immutable Hub account and get your client ID from [Immutable Hub](https://hub.immutable.com)
7777
- Set up the Unity project with the Immutable Passport SDK
78-
- Configure your project for the appropriate platform (WebGL, Android, iOS, macOS, Windows)
78+
- Configure your project for the appropriate platform
7979

8080
### Steps to Run the Example
8181
1. Open the Unity project and load the sample scene for Passport Initialisation

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,12 @@ private static void CreateCommandScript(string protocolName)
137137
" powershell -NoProfile -ExecutionPolicy Bypass -Command ^",
138138
" \"$ErrorActionPreference = 'Continue';\" ^",
139139
" \"$wshell = New-Object -ComObject wscript.shell;\" ^",
140-
" \"echo [$(Get-Date)] Attempting to activate process ID: %%A >> \\\"{logPath}\\\";\" ^",
140+
" \"Add-Content -Path \\\"{logPath}\\\" -Value ('[' + (Get-Date) + '] Attempting to activate process ID: ' + %%A);\" ^",
141141
" \"Start-Sleep -Milliseconds 100;\" ^",
142142
" \"$result = $wshell.AppActivate(%%A);\" ^",
143-
" \"echo [$(Get-Date)] AppActivate result: $result >> \\\"{logPath}\\\";\" ^",
144-
" \"if (-not $result) { echo [$(Get-Date)] Failed to activate window >> \\\"{logPath}\\\" }\"",
143+
" \"Add-Content -Path \\\"{logPath}\\\" -Value ('[' + (Get-Date) + '] AppActivate result: ' + $result);\" ^",
144+
" \"if (-not $result) { Add-Content -Path \\\"{logPath}\\\" -Value ('[' + (Get-Date) + '] Failed to activate window') }\" ^",
145+
" >nul 2>&1",
145146
" if errorlevel 1 echo [%date% %time%] PowerShell error: %errorlevel% >> \"%LOG_PATH%\"",
146147
" endlocal",
147148
" exit /b 0",
@@ -213,8 +214,19 @@ private static void RegisterProtocol(string protocolName)
213214
throw new Exception($"Failed to create PKCE registry key. Error code: {result}");
214215
}
215216

217+
// Set the default value for the protocol key to Application.productName
218+
// This is often used by Windows as the display name for the protocol
219+
string appProductName = Application.productName;
220+
uint productNameDataSize = (uint)((appProductName.Length + 1) * Marshal.SystemDefaultCharSize);
221+
int setDefaultResult = RegSetValueEx(hKey, null, 0, REG_SZ, appProductName, productNameDataSize);
222+
223+
if (setDefaultResult != 0)
224+
{
225+
PassportLogger.Warn($"Failed to set default display name for protocol '{protocolName}'. Error code: {setDefaultResult}");
226+
}
227+
216228
// Set URL Protocol value
217-
RegSetValueEx(hKey, "URL Protocol", 0, REG_SZ, string.Empty, 2);
229+
RegSetValueEx(hKey, "URL Protocol", 0, REG_SZ, string.Empty, (uint)(1 * Marshal.SystemDefaultCharSize));
218230

219231
// Create command subkey
220232
UIntPtr commandKey;

src/Packages/Passport/Runtime/Scripts/Public/Passport.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ private Passport()
137137
/// </summary>
138138
/// <param name="clientId">The client ID</param>
139139
/// <param name="environment">The environment to connect to</param>
140-
/// <param name="redirectUri">(Android, iOS, and macOS only) The URL where the browser will redirect after successful authentication.</param>
140+
/// <param name="redirectUri">The URL where the browser will redirect after successful authentication.</param>
141141
/// <param name="logoutRedirectUri">The URL where the browser will redirect after logout is complete.</param>
142142
/// <param name="engineStartupTimeoutMs">(Windows only) Timeout duration in milliseconds to wait for the default Windows browser engine to start.</param>
143143
/// <param name="webBrowserClient">(Windows only) Custom Windows browser to use instead of the default browser in the SDK.</param>

src/Packages/Passport/Samples~/SamplesScenesScripts/Scenes/Passport/SelectAuthMethod.unity

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1822,15 +1822,14 @@ MonoBehaviour:
18221822
18231823
18241824
1.
1825-
Authorisation Code Flow with Proof Key for Code Exchange (PKCE) is available
1826-
for Android, iOS, macOS and WebGL (not officially supported). This method provides
1825+
Authorisation Code Flow with Proof Key for Code Exchange (PKCE): This method provides
18271826
a seamless and secure authentication experience by opening a pop-up window on
18281827
macOS or an in-app browser on mobile devices. Players are automatically redirected
18291828
back to the game once authenticated, eliminating manual switching.
18301829
18311830
18321831
2. Device
1833-
Code Authorisation is available for Windows, Android, iOS and macOS. This method
1832+
Code Authorisation: This method
18341833
opens the player''s default browser and guides them through the authentication
18351834
flow.
18361835

src/Packages/Passport/Samples~/SamplesScenesScripts/Scripts/Passport/SelectAuthMethodScript.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public void UsePKCE()
5656
/// <summary>
5757
/// Initialises Passport.
5858
/// </summary>
59-
/// <param name="redirectUri">(Android, iOS and macOS only) The URL to which auth will redirect the browser after
59+
/// <param name="redirectUri">The URL to which auth will redirect the browser after
6060
/// authorisation has been granted by the user</param>
6161
/// <param name="logoutRedirectUri">The URL to which auth will redirect the browser
6262
/// after log out is complete</param>

0 commit comments

Comments
 (0)