Skip to content

[SDK-3205] Support WebGL #283

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

Merged
merged 17 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 14 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 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
30 changes: 21 additions & 9 deletions sample/Assets/Scripts/SelectAuthMethodScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ public class SelectAuthMethodScript : MonoBehaviour
[SerializeField] private GameObject TopPadding;
[SerializeField] private Text Output;
[SerializeField] private Button UseDeviceCodeAuthButton;
[SerializeField] private Button UsePKCEButton;
[SerializeField] private Button UsePKCEButton;
#pragma warning restore CS8618

void Start()
{
// Determine if PKCE is supported based on the platform
Expand All @@ -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,16 +53,25 @@ 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>
/// Initialises Passport.
/// </summary>
/// <param name="redirectUri">(Android, iOS and macOS only) The URL to which auth will redirect the browser after
/// authorisation has been granted by the user</param>
/// <param name="logoutRedirectUri">The URL to which auth will redirect the browser
/// after log out is complete</param>
private async void InitialisePassport(string redirectUri = null, string logoutRedirectUri = null)
{
ShowOutput("Initialising Passport...");
Expand All @@ -73,9 +82,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