Skip to content

Commit

Permalink
Merge pull request #283 from immutable/feature/sdk-3205-webgl
Browse files Browse the repository at this point in the history
[SDK-3205] Support WebGL
  • Loading branch information
andrew-yangy authored Oct 9, 2024
2 parents 01fdea8 + a8643ed commit b6b3eb6
Show file tree
Hide file tree
Showing 58 changed files with 1,292 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
VALIDATE_ALL_CODEBASE: true
DEFAULT_BRANCH: main
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
FILTER_REGEX_EXCLUDE: (.*src/Packages/Passport/Runtime/ThirdParty/.*|.*src/Packages/Passport/Runtime/Resources/.*|.*Plugins/.*|.*src/Packages/Passport/Runtime/Assets/ImmutableAndroid.androidlib/.*|.*src/Packages/Orderbook)
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)
VALIDATE_MARKDOWN: false
VALIDATE_GITLEAKS: false
VALIDATE_JSCPD: false
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ crashlytics-build.properties

sample-passport-unity-game/
sample/iosBuild
!/sample/webgl/Build/

# Android
src/Packages/Passport/Runtime/Assets/ImmutableAndroid.androidlib/**/*.meta
Expand Down
2 changes: 1 addition & 1 deletion sample/Assets/Scripts/AuthenticatedScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public async void Logout()
// Logout using the appropriate logout method
if (SampleAppManager.SupportsPKCE && SampleAppManager.UsePKCE)
{
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX || UNITY_WEBGL
await Passport.LogoutPKCE();
#endif
}
Expand Down
22 changes: 19 additions & 3 deletions sample/Assets/Scripts/SelectAuthMethodScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void Start()
/// </summary>
private bool IsPKCESupported()
{
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX || UNITY_WEBGL
return true;
#else
return false;
Expand All @@ -53,7 +53,20 @@ public void UseDeviceCodeAuth()
public void UsePKCE()
{
SampleAppManager.UsePKCE = true;
#if UNITY_WEBGL
string url = Application.absoluteURL;
Uri uri = new Uri(url);
string scheme = uri.Scheme;
string hostWithPort = uri.IsDefaultPort ? uri.Host : $"{uri.Host}:{uri.Port}";
string fullPath = uri.AbsolutePath.EndsWith("/") ? uri.AbsolutePath : uri.AbsolutePath.Substring(0, uri.AbsolutePath.LastIndexOf('/') + 1);

string redirectUri = $"{scheme}://{hostWithPort}{fullPath}callback.html";
string logoutRedirectUri = $"{scheme}://{hostWithPort}{fullPath}logout.html";

InitialisePassport(redirectUri: redirectUri, logoutRedirectUri: logoutRedirectUri);
#else
InitialisePassport(redirectUri: "imxsample://callback", logoutRedirectUri: "imxsample://callback/logout");
#endif
}

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

// Initialise Passport
string clientId = "ZJL7JvetcDFBNDlgRs5oJoxuAUUl6uQj";
string environment = Immutable.Passport.Model.Environment.SANDBOX;

#if UNITY_WEBGL
string clientId = "UnB98ngnXIZIEJWGJOjVe1BpCx5ix7qc";
#else
string clientId = "ZJL7JvetcDFBNDlgRs5oJoxuAUUl6uQj";
#endif
Passport passport = await Passport.Init(clientId, environment, redirectUri, logoutRedirectUri);

// Navigate to the unauthenticated scene after initialising Passport
Expand Down
6 changes: 3 additions & 3 deletions sample/Assets/Scripts/UnauthenticatedScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public async void Login()
// Login using the appropriate login method
if (SampleAppManager.SupportsPKCE && SampleAppManager.UsePKCE)
{
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX || UNITY_WEBGL
await Passport.LoginPKCE();
#endif
}
Expand Down Expand Up @@ -111,7 +111,7 @@ public async void Connect()
// Login and connect to IMX using the appropriate connect method
if (SampleAppManager.SupportsPKCE && SampleAppManager.UsePKCE)
{
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX || UNITY_WEBGL
await Passport.ConnectImxPKCE();
#endif
}
Expand Down Expand Up @@ -208,7 +208,7 @@ private async UniTask Logout()
// Logout using the appropriate logout method
if (SampleAppManager.SupportsPKCE && SampleAppManager.UsePKCE)
{
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX || UNITY_WEBGL
await Passport.LogoutPKCE();
#endif
}
Expand Down
Loading

0 comments on commit b6b3eb6

Please sign in to comment.