Skip to content

Commit 5cfb09d

Browse files
committed
chore: update sample app
1 parent 99aff36 commit 5cfb09d

File tree

4 files changed

+29
-17
lines changed

4 files changed

+29
-17
lines changed

sample/Assets/Scripts/AuthenticatedScript.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public async void Logout()
169169
// Logout using the appropriate logout method
170170
if (SampleAppManager.SupportsPKCE && SampleAppManager.UsePKCE)
171171
{
172-
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX
172+
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX || UNITY_WEBGL
173173
await Passport.LogoutPKCE();
174174
#endif
175175
}

sample/Assets/Scripts/SelectAuthMethodScript.cs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,29 @@ public class SelectAuthMethodScript : MonoBehaviour
1212
[SerializeField] private Text Output;
1313
[SerializeField] private Button UseDeviceCodeAuthButton;
1414
[SerializeField] private Button UsePKCEButton;
15+
string REDIRECT_URI = null;
16+
string LOGOUT_REIDIRECT_URI = "https://www.immutable.com";
1517
#pragma warning restore CS8618
16-
1718
void Start()
1819
{
20+
#if UNITY_WEBGL
21+
string url = Application.absoluteURL;
22+
Uri uri = new Uri(url);
23+
string scheme = uri.Scheme;
24+
string hostWithPort = uri.IsDefaultPort ? uri.Host : $"{uri.Host}:{uri.Port}";
25+
string fullPath = uri.AbsolutePath.EndsWith("/") ? uri.AbsolutePath : uri.AbsolutePath.Substring(0, uri.AbsolutePath.LastIndexOf('/') + 1);
26+
27+
REDIRECT_URI = $"{scheme}://{hostWithPort}{fullPath}callback.html";
28+
LOGOUT_REIDIRECT_URI = $"{scheme}://{hostWithPort}{fullPath}logout.html";
29+
#endif
30+
1931
// Determine if PKCE is supported based on the platform
2032
SampleAppManager.SupportsPKCE = IsPKCESupported();
2133

2234
// If PKCE is not supported, initialise Passport to use Device Code Auth
2335
if (!SampleAppManager.SupportsPKCE)
2436
{
25-
InitialisePassport(logoutRedirectUri: "https://www.immutable.com");
37+
InitialisePassport(redirectUri: REDIRECT_URI, logoutRedirectUri: LOGOUT_REIDIRECT_URI);
2638
}
2739
}
2840

@@ -31,7 +43,7 @@ void Start()
3143
/// </summary>
3244
private bool IsPKCESupported()
3345
{
34-
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX
46+
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX || UNITY_WEBGL
3547
return true;
3648
#else
3749
return false;
@@ -44,7 +56,7 @@ private bool IsPKCESupported()
4456
public void UseDeviceCodeAuth()
4557
{
4658
SampleAppManager.UsePKCE = false;
47-
InitialisePassport(logoutRedirectUri: "https://www.immutable.com");
59+
InitialisePassport(redirectUri: REDIRECT_URI, logoutRedirectUri: LOGOUT_REIDIRECT_URI);
4860
}
4961

5062
/// <summary>
@@ -53,7 +65,7 @@ public void UseDeviceCodeAuth()
5365
public void UsePKCE()
5466
{
5567
SampleAppManager.UsePKCE = true;
56-
InitialisePassport(redirectUri: "imxsample://callback", logoutRedirectUri: "imxsample://callback/logout");
68+
InitialisePassport(redirectUri: REDIRECT_URI, logoutRedirectUri: LOGOUT_REIDIRECT_URI);
5769
}
5870

5971
/// <summary>

sample/Assets/Scripts/UnauthenticatedScript.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public async void Login()
6969
// Login using the appropriate login method
7070
if (SampleAppManager.SupportsPKCE && SampleAppManager.UsePKCE)
7171
{
72-
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX
72+
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX || UNITY_WEBGL
7373
await Passport.LoginPKCE();
7474
#endif
7575
}
@@ -111,7 +111,7 @@ public async void Connect()
111111
// Login and connect to IMX using the appropriate connect method
112112
if (SampleAppManager.SupportsPKCE && SampleAppManager.UsePKCE)
113113
{
114-
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX
114+
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX || UNITY_WEBGL
115115
await Passport.ConnectImxPKCE();
116116
#endif
117117
}
@@ -208,7 +208,7 @@ private async UniTask Logout()
208208
// Logout using the appropriate logout method
209209
if (SampleAppManager.SupportsPKCE && SampleAppManager.UsePKCE)
210210
{
211-
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX
211+
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX || UNITY_WEBGL
212212
await Passport.LogoutPKCE();
213213
#endif
214214
}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -185,16 +185,16 @@ private async UniTask Initialise(
185185
// Initialise default browser client for Android, iOS, and macOS
186186
webBrowserClient = new GreeBrowserClient();
187187
#else
188-
throw new PassportException("Platform not supported");
188+
throw new PassportException("Platform not supported");
189189
#endif
190-
191-
// Set up browser communication
192-
BrowserCommunicationsManager communicationsManager = new BrowserCommunicationsManager(webBrowserClient);
193-
190+
191+
// Set up browser communication
192+
BrowserCommunicationsManager communicationsManager = new BrowserCommunicationsManager(webBrowserClient);
193+
194194
#if UNITY_WEBGL
195195
readySignalReceived = true;
196196
#else
197-
// Mark ready when browser is initialised and game bridge file is loaded
197+
// Mark ready when browser is initialised and game bridge file is loaded
198198
communicationsManager.OnReady += () => readySignalReceived = true;
199199
#endif
200200
// Set up Passport implementation
@@ -241,7 +241,7 @@ public async UniTask<bool> ConnectImx(bool useCachedSession = false, Nullable<lo
241241
return await GetPassportImpl().ConnectImx(useCachedSession, timeoutMs);
242242
}
243243

244-
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX || UNITY_WEBGL
244+
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX || UNITY_WEBGL
245245
/// <summary>
246246
/// Connects the user into Passport via PKCE auth.
247247
/// </summary>
@@ -283,7 +283,7 @@ public async UniTask Logout(bool hardLogout = true)
283283
await GetPassportImpl().Logout(hardLogout);
284284
}
285285

286-
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX
286+
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX || UNITY_WEBGL
287287
/// <summary>
288288
/// Logs the user out of Passport and removes any stored credentials.
289289
/// Recommended to use when logging in using PKCE flow - ConnectImxPKCE()

0 commit comments

Comments
 (0)