Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDK-3205] Support WebGL #283

Merged
merged 17 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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";
nattb8 marked this conversation as resolved.
Show resolved Hide resolved

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
Loading