Skip to content

[DX-3682] feat: windows pkce (alpha) #454

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 3 commits into from
Apr 16, 2025
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
12 changes: 6 additions & 6 deletions sample/Assets/Scenes/Passport/SelectAuthMethod.unity
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ MonoBehaviour:
m_TargetGraphic: {fileID: 416242725}
m_HandleRect: {fileID: 416242724}
m_Direction: 0
m_Value: 0
m_Value: 1
m_Size: 1
m_NumberOfSteps: 0
m_OnValueChanged:
Expand Down Expand Up @@ -1323,7 +1323,7 @@ MonoBehaviour:
m_TargetGraphic: {fileID: 167431872}
m_HandleRect: {fileID: 167431871}
m_Direction: 2
m_Value: 1
m_Value: 0
m_Size: 1
m_NumberOfSteps: 0
m_OnValueChanged:
Expand Down Expand Up @@ -1673,8 +1673,8 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 1016.24, y: 0}
m_SizeDelta: {x: 1992.48, y: 0}
m_AnchoredPosition: {x: 841.51855, y: 0}
m_SizeDelta: {x: 1643.0371, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1661390145
MonoBehaviour:
Expand Down Expand Up @@ -1768,8 +1768,8 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 1016.24, y: 0}
m_SizeDelta: {x: 1992.48, y: 0}
m_AnchoredPosition: {x: 841.51855, y: 0}
m_SizeDelta: {x: 1643.0371, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1688502349
MonoBehaviour:
Expand Down
4 changes: 1 addition & 3 deletions sample/Assets/Scripts/Passport/AuthenticatedScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,9 @@ public async void Logout()
try
{
// Logout using the appropriate logout method
if (SampleAppManager.SupportsPKCE && SampleAppManager.UsePKCE)
if (SampleAppManager.UsePKCE)
{
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX || UNITY_WEBGL
await Passport.LogoutPKCE();
#endif
}
else
{
Expand Down
5 changes: 0 additions & 5 deletions sample/Assets/Scripts/Passport/SampleAppManager.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
public static class SampleAppManager
{
/// <summary>
/// Indicates whether the running platform supports PKCE.
/// </summary>
public static bool SupportsPKCE { get; set; }

/// <summary>
/// Indicates whether the selected authentication method is PKCE.
/// </summary>
Expand Down
21 changes: 0 additions & 21 deletions sample/Assets/Scripts/Passport/SelectAuthMethodScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,9 @@ public class SelectAuthMethodScript : MonoBehaviour

void Start()
{
// Determine if PKCE is supported based on the platform
SampleAppManager.SupportsPKCE = IsPKCESupported();

// WebGL does not support Device Code Auth, so we'll use PKCE by default instead.
#if UNITY_WEBGL
UsePKCE();
#else
// If PKCE is not supported, initialise Passport to use Device Code Auth
if (!SampleAppManager.SupportsPKCE)
{
UseDeviceCodeAuth();
}
#endif
}

/// <summary>
/// Checks if the current platform supports PKCE authentication.
/// </summary>
private bool IsPKCESupported()
{
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX || UNITY_WEBGL
return true;
#else
return false;
#endif
}

Expand Down
12 changes: 3 additions & 9 deletions sample/Assets/Scripts/Passport/UnauthenticatedScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,9 @@ public async void Login()
try
{
// Login using the appropriate login method
if (SampleAppManager.SupportsPKCE && SampleAppManager.UsePKCE)
if (SampleAppManager.UsePKCE)
{
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX || UNITY_WEBGL
await Passport.LoginPKCE();
#endif
}
else
{
Expand Down Expand Up @@ -109,11 +107,9 @@ public async void Connect()
try
{
// Login and connect to IMX using the appropriate connect method
if (SampleAppManager.SupportsPKCE && SampleAppManager.UsePKCE)
if (SampleAppManager.UsePKCE)
{
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX || UNITY_WEBGL
await Passport.ConnectImxPKCE();
#endif
}
else
{
Expand Down Expand Up @@ -206,11 +202,9 @@ private async UniTask Logout()
try
{
// Logout using the appropriate logout method
if (SampleAppManager.SupportsPKCE && SampleAppManager.UsePKCE)
if (SampleAppManager.UsePKCE)
{
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX || UNITY_WEBGL
await Passport.LogoutPKCE();
#endif
}
else
{
Expand Down
16 changes: 14 additions & 2 deletions sample/Tests/test/test_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ def tearDownClass(cls):
stop_sample_app()

def test_1_device_code_login(self):
# Select use device code auth
self.altdriver.find_object(By.NAME, "DeviceCodeAuth").tap()

# Wait for unauthenticated screen
self.altdriver.wait_for_current_scene_to_be("UnauthenticatedScene")

Expand Down Expand Up @@ -48,9 +51,12 @@ def test_1_device_code_login(self):
if attempt == 0:
# Reset app

# Relogin
# Relogin (optional: only if the button is present)
print("Try reset the app and log out once...")
self.altdriver.wait_for_object(By.NAME, "ReloginBtn").tap()
try:
self.altdriver.wait_for_object(By.NAME, "ReloginBtn").tap()
except Exception as e:
print("ReloginBtn not found, skipping relogin step. User may already be in AuthenticatedScene.")

# Wait for authenticated screen
self.altdriver.wait_for_current_scene_to_be("AuthenticatedScene")
Expand Down Expand Up @@ -95,6 +101,9 @@ def test_6_relogin(self):
self.altdriver = AltDriver()
time.sleep(5)

# Select use device code auth
self.altdriver.find_object(By.NAME, "DeviceCodeAuth").tap()

# Relogin
print("Re-logging in...")
self.altdriver.wait_for_object(By.NAME, "ReloginBtn").tap()
Expand Down Expand Up @@ -124,6 +133,9 @@ def test_7_reconnect_device_code_connect_imx(self):
self.altdriver = AltDriver()
time.sleep(5)

# Select use device code auth
self.altdriver.find_object(By.NAME, "DeviceCodeAuth").tap()

# Reconnect
print("Reconnecting...")
self.altdriver.wait_for_object(By.NAME, "ReconnectBtn").tap()
Expand Down
8 changes: 8 additions & 0 deletions src/Packages/Passport/Private.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/Packages/Passport/Private/Helpers.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading