From e13be2d9a4fc91563d2d801c88ba07478086488f Mon Sep 17 00:00:00 2001 From: Natalie Bunduwongse Date: Tue, 4 Nov 2025 14:37:27 +1300 Subject: [PATCH] feat: handle hosted login page for windows --- .../Runtime/Scripts/Private/PassportImpl.cs | 20 +++++++++++++++++++ .../Runtime/Scripts/Public/Passport.cs | 12 +++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/Packages/Passport/Runtime/Scripts/Private/PassportImpl.cs b/src/Packages/Passport/Runtime/Scripts/Private/PassportImpl.cs index 2a492d56d..e0ab8ce9c 100644 --- a/src/Packages/Passport/Runtime/Scripts/Private/PassportImpl.cs +++ b/src/Packages/Passport/Runtime/Scripts/Private/PassportImpl.cs @@ -50,6 +50,13 @@ public async UniTask Init(string clientId, string environment, string redirectUr string logoutRedirectUri, string? deeplink = null) { _redirectUri = redirectUri; +#if UNITY_STANDALONE_WIN || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN) + if (redirectUri.Contains(GetHostedLoginPageUrl(environment))) { + Uri uri = new Uri(redirectUri); + string redirectUriParam = uri.GetQueryParameter("redirect_uri"); + _redirectUri = redirectUriParam; + } +#endif _logoutRedirectUri = logoutRedirectUri; #if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX || UNITY_WEBGL @@ -772,6 +779,19 @@ protected virtual async void Track(string eventName, bool? success = null, Dicti { await _analytics.Track(_communicationsManager, eventName, success, properties); } + +#if UNITY_STANDALONE_WIN || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN) + /// + /// Gets the hosted login page URL for the specified environment. + /// This is used for Windows login redirect flow. + /// + public static string GetHostedLoginPageUrl(string environment) + { + return environment == Immutable.Passport.Model.Environment.DEVELOPMENT + ? "https://auth.dev.immutable.com/im-logged-in" + : "https://auth.immutable.com/im-logged-in"; + } +#endif } #if UNITY_ANDROID diff --git a/src/Packages/Passport/Runtime/Scripts/Public/Passport.cs b/src/Packages/Passport/Runtime/Scripts/Public/Passport.cs index f028b1140..b74b0ba26 100644 --- a/src/Packages/Passport/Runtime/Scripts/Public/Passport.cs +++ b/src/Packages/Passport/Runtime/Scripts/Public/Passport.cs @@ -153,7 +153,7 @@ string logoutRedirectUri ) { #if UNITY_STANDALONE_WIN || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN) - ValidateWindowsProtocols(redirectUri, logoutRedirectUri); + ValidateWindowsProtocols(environment, redirectUri, logoutRedirectUri); #endif if (Instance == null) @@ -705,8 +705,16 @@ private void DisposeAll() /// Validates that custom protocols are used for Windows platforms instead of http/https. /// Windows uses registry-based deep linking which requires custom protocols. /// - private static void ValidateWindowsProtocols(string redirectUri, string logoutRedirectUri) + private static void ValidateWindowsProtocols(string environment, string redirectUri, string logoutRedirectUri) { + // Allow the special hosted login page URL format for Windows login redirect + string hostedLoginPageUrl = PassportImpl.GetHostedLoginPageUrl(environment); + + if (redirectUri.Contains(hostedLoginPageUrl)) + { + return; + } + if (IsHttpProtocol(redirectUri)) { throw new PassportException(