Skip to content

[ID-3737] fix: windows pkce cmd errors, protocol name, pkce docs #481

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions sample/Assets/Scenes/Passport/SelectAuthMethod.unity
Original file line number Diff line number Diff line change
Expand Up @@ -1866,21 +1866,20 @@ MonoBehaviour:


1.
Authorisation Code Flow with Proof Key for Code Exchange (PKCE) is available
for Android, iOS, macOS and WebGL (not officially supported). This method provides
Authorisation Code Flow with Proof Key for Code Exchange (PKCE): This method provides
a seamless and secure authentication experience by opening a pop-up window on
macOS or an in-app browser on mobile devices. Players are automatically redirected
desktop or an in-app browser on mobile devices. Players are automatically redirected
back to the game once authenticated, eliminating manual switching.


2. Device
Code Authorisation is available for Windows, Android, iOS and macOS. This method
Code Authorisation: This method
opens the player''s default browser and guides them through the authentication
flow.


Recommendation: Whenever possible, use the PKCE flow as it is the
most secure and seamless method for authentication on Android, iOS and macOS.'
most secure and seamless method for authentication.'
--- !u!222 &1688502351
CanvasRenderer:
m_ObjectHideFlags: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void UsePKCE()
/// <summary>
/// Initialises Passport.
/// </summary>
/// <param name="redirectUri">(Android, iOS and macOS only) The URL to which auth will redirect the browser after
/// <param name="redirectUri">The URL to which auth will redirect the browser after
/// authorisation has been granted by the user</param>
/// <param name="logoutRedirectUri">The URL to which auth will redirect the browser
/// after log out is complete</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ For PKCE authentication, the redirect URIs must be configured correctly based on
### Prerequisites
- Create an Immutable Hub account and get your client ID from [Immutable Hub](https://hub.immutable.com)
- Set up the Unity project with the Immutable Passport SDK
- Configure your project for the appropriate platform (WebGL, Android, iOS, macOS, Windows)
- Configure your project for the appropriate platform

### Steps to Run the Example
1. Open the Unity project and load the sample scene for Passport Initialisation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,12 @@ private static void CreateCommandScript(string protocolName)
" powershell -NoProfile -ExecutionPolicy Bypass -Command ^",
" \"$ErrorActionPreference = 'Continue';\" ^",
" \"$wshell = New-Object -ComObject wscript.shell;\" ^",
" \"echo [$(Get-Date)] Attempting to activate process ID: %%A >> \\\"{logPath}\\\";\" ^",
" \"Add-Content -Path \\\"{logPath}\\\" -Value ('[' + (Get-Date) + '] Attempting to activate process ID: ' + %%A);\" ^",
" \"Start-Sleep -Milliseconds 100;\" ^",
" \"$result = $wshell.AppActivate(%%A);\" ^",
" \"echo [$(Get-Date)] AppActivate result: $result >> \\\"{logPath}\\\";\" ^",
" \"if (-not $result) { echo [$(Get-Date)] Failed to activate window >> \\\"{logPath}\\\" }\"",
" \"Add-Content -Path \\\"{logPath}\\\" -Value ('[' + (Get-Date) + '] AppActivate result: ' + $result);\" ^",
" \"if (-not $result) { Add-Content -Path \\\"{logPath}\\\" -Value ('[' + (Get-Date) + '] Failed to activate window') }\" ^",
" >nul 2>&1",
" if errorlevel 1 echo [%date% %time%] PowerShell error: %errorlevel% >> \"%LOG_PATH%\"",
" endlocal",
" exit /b 0",
Expand Down Expand Up @@ -213,8 +214,19 @@ private static void RegisterProtocol(string protocolName)
throw new Exception($"Failed to create PKCE registry key. Error code: {result}");
}

// Set the default value for the protocol key to Application.productName
// This is often used by Windows as the display name for the protocol
string appProductName = Application.productName;
uint productNameDataSize = (uint)((appProductName.Length + 1) * Marshal.SystemDefaultCharSize);
int setDefaultResult = RegSetValueEx(hKey, null, 0, REG_SZ, appProductName, productNameDataSize);

if (setDefaultResult != 0)
{
PassportLogger.Warn($"Failed to set default display name for protocol '{protocolName}'. Error code: {setDefaultResult}");
}

// Set URL Protocol value
RegSetValueEx(hKey, "URL Protocol", 0, REG_SZ, string.Empty, 2);
RegSetValueEx(hKey, "URL Protocol", 0, REG_SZ, string.Empty, (uint)(1 * Marshal.SystemDefaultCharSize));

// Create command subkey
UIntPtr commandKey;
Expand Down
2 changes: 1 addition & 1 deletion src/Packages/Passport/Runtime/Scripts/Public/Passport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private Passport()
/// </summary>
/// <param name="clientId">The client ID</param>
/// <param name="environment">The environment to connect to</param>
/// <param name="redirectUri">(Android, iOS, and macOS only) The URL where the browser will redirect after successful authentication.</param>
/// <param name="redirectUri">The URL where the browser will redirect after successful authentication.</param>
/// <param name="logoutRedirectUri">The URL where the browser will redirect after logout is complete.</param>
/// <param name="engineStartupTimeoutMs">(Windows only) Timeout duration in milliseconds to wait for the default Windows browser engine to start.</param>
/// <param name="webBrowserClient">(Windows only) Custom Windows browser to use instead of the default browser in the SDK.</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1822,15 +1822,14 @@ MonoBehaviour:


1.
Authorisation Code Flow with Proof Key for Code Exchange (PKCE) is available
for Android, iOS, macOS and WebGL (not officially supported). This method provides
Authorisation Code Flow with Proof Key for Code Exchange (PKCE): This method provides
a seamless and secure authentication experience by opening a pop-up window on
macOS or an in-app browser on mobile devices. Players are automatically redirected
back to the game once authenticated, eliminating manual switching.


2. Device
Code Authorisation is available for Windows, Android, iOS and macOS. This method
Code Authorisation: This method
opens the player''s default browser and guides them through the authentication
flow.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void UsePKCE()
/// <summary>
/// Initialises Passport.
/// </summary>
/// <param name="redirectUri">(Android, iOS and macOS only) The URL to which auth will redirect the browser after
/// <param name="redirectUri">The URL to which auth will redirect the browser after
/// authorisation has been granted by the user</param>
/// <param name="logoutRedirectUri">The URL to which auth will redirect the browser
/// after log out is complete</param>
Expand Down
Loading