Skip to content

Commit b6b3eb6

Browse files
authored
Merge pull request #283 from immutable/feature/sdk-3205-webgl
[SDK-3205] Support WebGL
2 parents 01fdea8 + a8643ed commit b6b3eb6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1292
-35
lines changed

.github/workflows/linter.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
VALIDATE_ALL_CODEBASE: true
5858
DEFAULT_BRANCH: main
5959
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
60-
FILTER_REGEX_EXCLUDE: (.*src/Packages/Passport/Runtime/ThirdParty/.*|.*src/Packages/Passport/Runtime/Resources/.*|.*Plugins/.*|.*src/Packages/Passport/Runtime/Assets/ImmutableAndroid.androidlib/.*|.*src/Packages/Orderbook)
60+
FILTER_REGEX_EXCLUDE: (.*src/Packages/Passport/Runtime/ThirdParty/.*|.*src/Packages/Passport/Runtime/Resources/.*|.*Plugins/.*|.*src/Packages/Passport/Runtime/Assets/ImmutableAndroid.androidlib/.*|.*src/Packages/Orderbook|.*sample)
6161
VALIDATE_MARKDOWN: false
6262
VALIDATE_GITLEAKS: false
6363
VALIDATE_JSCPD: false

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ crashlytics-build.properties
8181

8282
sample-passport-unity-game/
8383
sample/iosBuild
84+
!/sample/webgl/Build/
8485

8586
# Android
8687
src/Packages/Passport/Runtime/Assets/ImmutableAndroid.androidlib/**/*.meta

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: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void Start()
3131
/// </summary>
3232
private bool IsPKCESupported()
3333
{
34-
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX
34+
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX || UNITY_WEBGL
3535
return true;
3636
#else
3737
return false;
@@ -53,7 +53,20 @@ public void UseDeviceCodeAuth()
5353
public void UsePKCE()
5454
{
5555
SampleAppManager.UsePKCE = true;
56+
#if UNITY_WEBGL
57+
string url = Application.absoluteURL;
58+
Uri uri = new Uri(url);
59+
string scheme = uri.Scheme;
60+
string hostWithPort = uri.IsDefaultPort ? uri.Host : $"{uri.Host}:{uri.Port}";
61+
string fullPath = uri.AbsolutePath.EndsWith("/") ? uri.AbsolutePath : uri.AbsolutePath.Substring(0, uri.AbsolutePath.LastIndexOf('/') + 1);
62+
63+
string redirectUri = $"{scheme}://{hostWithPort}{fullPath}callback.html";
64+
string logoutRedirectUri = $"{scheme}://{hostWithPort}{fullPath}logout.html";
65+
66+
InitialisePassport(redirectUri: redirectUri, logoutRedirectUri: logoutRedirectUri);
67+
#else
5668
InitialisePassport(redirectUri: "imxsample://callback", logoutRedirectUri: "imxsample://callback/logout");
69+
#endif
5770
}
5871

5972
/// <summary>
@@ -73,9 +86,12 @@ private async void InitialisePassport(string redirectUri = null, string logoutRe
7386
Passport.LogLevel = LogLevel.Info;
7487

7588
// Initialise Passport
76-
string clientId = "ZJL7JvetcDFBNDlgRs5oJoxuAUUl6uQj";
7789
string environment = Immutable.Passport.Model.Environment.SANDBOX;
78-
90+
#if UNITY_WEBGL
91+
string clientId = "UnB98ngnXIZIEJWGJOjVe1BpCx5ix7qc";
92+
#else
93+
string clientId = "ZJL7JvetcDFBNDlgRs5oJoxuAUUl6uQj";
94+
#endif
7995
Passport passport = await Passport.Init(clientId, environment, redirectUri, logoutRedirectUri);
8096

8197
// Navigate to the unauthenticated scene after initialising Passport

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
}

0 commit comments

Comments
 (0)