Skip to content

Commit cea9736

Browse files
authored
Merge pull request #604 from immutable/feat/windows-login-redirect
feat: handle hosted login page for windows
2 parents cd1da31 + e13be2d commit cea9736

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ public async UniTask Init(string clientId, string environment, string redirectUr
5050
string logoutRedirectUri, string? deeplink = null)
5151
{
5252
_redirectUri = redirectUri;
53+
#if UNITY_STANDALONE_WIN || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN)
54+
if (redirectUri.Contains(GetHostedLoginPageUrl(environment))) {
55+
Uri uri = new Uri(redirectUri);
56+
string redirectUriParam = uri.GetQueryParameter("redirect_uri");
57+
_redirectUri = redirectUriParam;
58+
}
59+
#endif
5360
_logoutRedirectUri = logoutRedirectUri;
5461

5562
#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
772779
{
773780
await _analytics.Track(_communicationsManager, eventName, success, properties);
774781
}
782+
783+
#if UNITY_STANDALONE_WIN || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN)
784+
/// <summary>
785+
/// Gets the hosted login page URL for the specified environment.
786+
/// This is used for Windows login redirect flow.
787+
/// </summary>
788+
public static string GetHostedLoginPageUrl(string environment)
789+
{
790+
return environment == Immutable.Passport.Model.Environment.DEVELOPMENT
791+
? "https://auth.dev.immutable.com/im-logged-in"
792+
: "https://auth.immutable.com/im-logged-in";
793+
}
794+
#endif
775795
}
776796

777797
#if UNITY_ANDROID

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ string logoutRedirectUri
153153
)
154154
{
155155
#if UNITY_STANDALONE_WIN || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN)
156-
ValidateWindowsProtocols(redirectUri, logoutRedirectUri);
156+
ValidateWindowsProtocols(environment, redirectUri, logoutRedirectUri);
157157
#endif
158158

159159
if (Instance == null)
@@ -705,8 +705,16 @@ private void DisposeAll()
705705
/// Validates that custom protocols are used for Windows platforms instead of http/https.
706706
/// Windows uses registry-based deep linking which requires custom protocols.
707707
/// </summary>
708-
private static void ValidateWindowsProtocols(string redirectUri, string logoutRedirectUri)
708+
private static void ValidateWindowsProtocols(string environment, string redirectUri, string logoutRedirectUri)
709709
{
710+
// Allow the special hosted login page URL format for Windows login redirect
711+
string hostedLoginPageUrl = PassportImpl.GetHostedLoginPageUrl(environment);
712+
713+
if (redirectUri.Contains(hostedLoginPageUrl))
714+
{
715+
return;
716+
}
717+
710718
if (IsHttpProtocol(redirectUri))
711719
{
712720
throw new PassportException(

0 commit comments

Comments
 (0)