From 2e20da342a240eaaccdadefb291e981aa99b0547 Mon Sep 17 00:00:00 2001 From: Natalie Bunduwongse Date: Thu, 11 Jul 2024 15:16:23 +1200 Subject: [PATCH] feat: ability to set device code auth timeout --- .../Assets/Scenes/UnauthenticatedScene.unity | 329 +++++++++++++++++- .../Assets/Scripts/UnauthenticatedScript.cs | 26 +- .../Core/BrowserCommunicationsManager.cs | 6 +- .../Runtime/Scripts/Private/PassportImpl.cs | 15 +- .../Runtime/Scripts/Public/Passport.cs | 2 + .../Tests/Runtime/Scripts/PassportTests.cs | 2 +- 6 files changed, 351 insertions(+), 29 deletions(-) diff --git a/sample/Assets/Scenes/UnauthenticatedScene.unity b/sample/Assets/Scenes/UnauthenticatedScene.unity index 3aa97dc6..fc2ae7b5 100644 --- a/sample/Assets/Scenes/UnauthenticatedScene.unity +++ b/sample/Assets/Scenes/UnauthenticatedScene.unity @@ -286,8 +286,8 @@ MonoBehaviour: m_TargetGraphic: {fileID: 416242725} m_HandleRect: {fileID: 416242724} m_Direction: 0 - m_Value: 1 - m_Size: 1 + m_Value: 0 + m_Size: 0.99999994 m_NumberOfSteps: 0 m_OnValueChanged: m_PersistentCalls: @@ -449,6 +449,86 @@ RectTransform: m_AnchoredPosition: {x: -0.000030040741, y: 0} m_SizeDelta: {x: 0, y: 0} m_Pivot: {x: 0, y: 1} +--- !u!1 &160623835 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 160623836} + - component: {fileID: 160623838} + - component: {fileID: 160623837} + m_Layer: 5 + m_Name: Text (Legacy) + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &160623836 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 160623835} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 233062548} + m_RootOrder: 1 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 1, y: 1} + m_AnchoredPosition: {x: 0, y: -0.5} + m_SizeDelta: {x: -20, y: -13} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &160623837 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 160623835} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_FontData: + m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0} + m_FontSize: 14 + m_FontStyle: 0 + m_BestFit: 0 + m_MinSize: 10 + m_MaxSize: 40 + m_Alignment: 0 + m_AlignByGeometry: 0 + m_RichText: 0 + m_HorizontalOverflow: 1 + m_VerticalOverflow: 0 + m_LineSpacing: 1 + m_Text: +--- !u!222 &160623838 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 160623835} + m_CullTransparentMesh: 1 --- !u!1 &167431870 GameObject: m_ObjectHideFlags: 0 @@ -560,7 +640,7 @@ RectTransform: - {fileID: 27701370} - {fileID: 1403438476} m_Father: {fileID: 1850628784} - m_RootOrder: 9 + m_RootOrder: 10 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 1, y: 0} @@ -635,6 +715,153 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 172384058} m_CullTransparentMesh: 1 +--- !u!1 &233062547 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 233062548} + - component: {fileID: 233062551} + - component: {fileID: 233062550} + - component: {fileID: 233062549} + m_Layer: 5 + m_Name: DeviceCodeTimeoutMs + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 0 +--- !u!224 &233062548 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 233062547} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: + - {fileID: 2127039960} + - {fileID: 160623836} + m_Father: {fileID: 1850628784} + m_RootOrder: 6 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 1} + m_AnchorMax: {x: 0, y: 1} + m_AnchoredPosition: {x: 440, y: -100} + m_SizeDelta: {x: 300, y: 30} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &233062549 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 233062547} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: d199490a83bb2b844b9695cbf13b01ef, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Navigation: + m_Mode: 3 + m_WrapAround: 0 + m_SelectOnUp: {fileID: 0} + m_SelectOnDown: {fileID: 0} + m_SelectOnLeft: {fileID: 0} + m_SelectOnRight: {fileID: 0} + m_Transition: 1 + m_Colors: + m_NormalColor: {r: 1, g: 1, b: 1, a: 1} + m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} + m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1} + m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} + m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608} + m_ColorMultiplier: 1 + m_FadeDuration: 0.1 + m_SpriteState: + m_HighlightedSprite: {fileID: 0} + m_PressedSprite: {fileID: 0} + m_SelectedSprite: {fileID: 0} + m_DisabledSprite: {fileID: 0} + m_AnimationTriggers: + m_NormalTrigger: Normal + m_HighlightedTrigger: Highlighted + m_PressedTrigger: Pressed + m_SelectedTrigger: Selected + m_DisabledTrigger: Disabled + m_Interactable: 1 + m_TargetGraphic: {fileID: 233062550} + m_TextComponent: {fileID: 160623837} + m_Placeholder: {fileID: 2127039961} + m_ContentType: 0 + m_InputType: 0 + m_AsteriskChar: 42 + m_KeyboardType: 0 + m_LineType: 0 + m_HideMobileInput: 0 + m_CharacterValidation: 0 + m_CharacterLimit: 0 + m_OnSubmit: + m_PersistentCalls: + m_Calls: [] + m_OnDidEndEdit: + m_PersistentCalls: + m_Calls: [] + m_OnValueChanged: + m_PersistentCalls: + m_Calls: [] + m_CaretColor: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1} + m_CustomCaretColor: 0 + m_SelectionColor: {r: 0.65882355, g: 0.80784315, b: 1, a: 0.7529412} + m_Text: + m_CaretBlinkRate: 0.85 + m_CaretWidth: 1 + m_ReadOnly: 0 + m_ShouldActivateOnSelect: 1 +--- !u!114 &233062550 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 233062547} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_Sprite: {fileID: 10911, guid: 0000000000000000f000000000000000, type: 0} + m_Type: 1 + m_PreserveAspect: 0 + m_FillCenter: 1 + m_FillMethod: 4 + m_FillAmount: 1 + m_FillClockwise: 1 + m_FillOrigin: 0 + m_UseSpriteMesh: 0 + m_PixelsPerUnitMultiplier: 1 +--- !u!222 &233062551 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 233062547} + m_CullTransparentMesh: 1 --- !u!1 &270318904 GameObject: m_ObjectHideFlags: 0 @@ -668,7 +895,7 @@ RectTransform: m_Children: - {fileID: 778650640} m_Father: {fileID: 1850628784} - m_RootOrder: 7 + m_RootOrder: 8 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 1} m_AnchorMax: {x: 0, y: 1} @@ -1173,7 +1400,7 @@ RectTransform: m_Children: - {fileID: 1173574367} m_Father: {fileID: 1850628784} - m_RootOrder: 6 + m_RootOrder: 7 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 1} m_AnchorMax: {x: 0, y: 1} @@ -1526,7 +1753,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!224 &891178850 RectTransform: m_ObjectHideFlags: 0 @@ -2019,6 +2246,7 @@ MonoBehaviour: SelectLoginMethod: {fileID: 1523853787} UseDeviceCodeAuthToggle: {fileID: 1897314389} UsePKCEToggle: {fileID: 891178851} + DeviceCodeTimeoutMs: {fileID: 233062549} --- !u!4 &1192763473 Transform: m_ObjectHideFlags: 0 @@ -2154,7 +2382,7 @@ MonoBehaviour: m_TargetGraphic: {fileID: 167431872} m_HandleRect: {fileID: 167431871} m_Direction: 2 - m_Value: 0 + m_Value: 1 m_Size: 1 m_NumberOfSteps: 0 m_OnValueChanged: @@ -2252,7 +2480,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!224 &1523853786 RectTransform: m_ObjectHideFlags: 0 @@ -2416,7 +2644,7 @@ RectTransform: m_Children: - {fileID: 819421122} m_Father: {fileID: 1850628784} - m_RootOrder: 8 + m_RootOrder: 9 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 1} m_AnchorMax: {x: 0, y: 1} @@ -2872,6 +3100,7 @@ RectTransform: - {fileID: 1897314388} - {fileID: 892906553} - {fileID: 291915219} + - {fileID: 233062548} - {fileID: 613764572} - {fileID: 270318905} - {fileID: 1582459301} @@ -3038,7 +3267,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!224 &1897314388 RectTransform: m_ObjectHideFlags: 0 @@ -3109,3 +3338,83 @@ MonoBehaviour: m_PersistentCalls: m_Calls: [] m_IsOn: 0 +--- !u!1 &2127039959 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2127039960} + - component: {fileID: 2127039962} + - component: {fileID: 2127039961} + m_Layer: 5 + m_Name: Placeholder + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &2127039960 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2127039959} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 233062548} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 1, y: 1} + m_AnchoredPosition: {x: 0, y: -0.5} + m_SizeDelta: {x: -20, y: -13} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &2127039961 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2127039959} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 0.5} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_FontData: + m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0} + m_FontSize: 14 + m_FontStyle: 2 + m_BestFit: 0 + m_MinSize: 10 + m_MaxSize: 40 + m_Alignment: 0 + m_AlignByGeometry: 0 + m_RichText: 1 + m_HorizontalOverflow: 0 + m_VerticalOverflow: 0 + m_LineSpacing: 1 + m_Text: Timeout in ms (leave blank for no timeout) +--- !u!222 &2127039962 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2127039959} + m_CullTransparentMesh: 1 diff --git a/sample/Assets/Scripts/UnauthenticatedScript.cs b/sample/Assets/Scripts/UnauthenticatedScript.cs index db098f22..c9a6b604 100644 --- a/sample/Assets/Scripts/UnauthenticatedScript.cs +++ b/sample/Assets/Scripts/UnauthenticatedScript.cs @@ -18,6 +18,7 @@ public class UnauthenticatedScript : MonoBehaviour [SerializeField] private Text SelectLoginMethod; [SerializeField] private Toggle UseDeviceCodeAuthToggle; [SerializeField] private Toggle UsePKCEToggle; + [SerializeField] private InputField DeviceCodeTimeoutMs; private Passport passport; #pragma warning restore CS8618 @@ -58,6 +59,7 @@ void Start() ReconnectButton.gameObject.SetActive(false); LoginButton.gameObject.SetActive(true); ConnectButton.gameObject.SetActive(true); + DeviceCodeTimeoutMs.gameObject.SetActive(!SampleAppManager.UsePKCE); passport = Passport.Instance; } } @@ -99,6 +101,7 @@ private async void InitialisePassport() ReconnectButton.gameObject.SetActive(hasCredsSaved); LoginButton.gameObject.SetActive(!hasCredsSaved); ConnectButton.gameObject.SetActive(!hasCredsSaved); + DeviceCodeTimeoutMs.gameObject.SetActive(!hasCredsSaved && !SampleAppManager.UsePKCE); SampleAppManager.InitialisedPassport = true; ShowOutput("Ready"); @@ -118,8 +121,8 @@ public async void Login() { try { - ShowOutput("Called Login()..."); - LoginButton.gameObject.SetActive(false); + Nullable timeoutMs = GetDeviceCodeTimeoutMs(); ; + ShowOutput($"Called Login() (timeout: {(timeoutMs != null ? timeoutMs.ToString() + "ms" : "none")})..."); #if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX if (SampleAppManager.UsePKCE) @@ -128,10 +131,10 @@ public async void Login() } else { - await passport.Login(); + await passport.Login(timeoutMs: timeoutMs); } #else - await passport.Login(); + await passport.Login(timeoutMs: timeoutMs); #endif SampleAppManager.IsConnected = false; @@ -156,7 +159,6 @@ public async void Login() Debug.Log(error); ShowOutput(error); - LoginButton.gameObject.SetActive(true); } } @@ -190,8 +192,8 @@ public async void Connect() { try { - ShowOutput("Called Connect()..."); - ConnectButton.gameObject.SetActive(false); + Nullable timeoutMs = GetDeviceCodeTimeoutMs(); + ShowOutput($"Called Connect() (timeout: {(timeoutMs != null ? timeoutMs.ToString() + "ms" : "none")})..."); #if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX if (SampleAppManager.UsePKCE) @@ -200,10 +202,10 @@ public async void Connect() } else { - await passport.ConnectImx(); + await passport.ConnectImx(timeoutMs: timeoutMs); } #else - await passport.ConnectImx(); + await passport.ConnectImx(timeoutMs: timeoutMs); #endif SampleAppManager.IsConnected = true; @@ -228,7 +230,6 @@ public async void Connect() Debug.Log(error); ShowOutput(error); - ConnectButton.gameObject.SetActive(true); } } @@ -292,6 +293,11 @@ public void ClearStorageAndCache() #endif } + private Nullable GetDeviceCodeTimeoutMs() + { + return String.IsNullOrEmpty(DeviceCodeTimeoutMs.text) ? null : long.Parse(DeviceCodeTimeoutMs.text); + } + private void NavigateToAuthenticatedScene() { passport.OnAuthEvent -= OnPassportAuthEvent; diff --git a/src/Packages/Passport/Runtime/Scripts/Private/Core/BrowserCommunicationsManager.cs b/src/Packages/Passport/Runtime/Scripts/Private/Core/BrowserCommunicationsManager.cs index 3fefde67..4a4c2ed0 100644 --- a/src/Packages/Passport/Runtime/Scripts/Private/Core/BrowserCommunicationsManager.cs +++ b/src/Packages/Passport/Runtime/Scripts/Private/Core/BrowserCommunicationsManager.cs @@ -23,7 +23,7 @@ public interface IBrowserCommunicationsManager event OnUnityPostMessageErrorDelegate OnPostMessageError; void SetCallTimeout(int ms); void LaunchAuthURL(string url, string redirectUri); - UniTask Call(string fxName, string data = null, bool ignoreTimeout = false); + UniTask Call(string fxName, string data = null, bool ignoreTimeout = false, Nullable timeoutMs = null); #if (UNITY_IPHONE && !UNITY_EDITOR) || (UNITY_ANDROID && !UNITY_EDITOR) void ClearCache(bool includeDiskFiles); void ClearStorage(); @@ -71,7 +71,7 @@ public void SetCallTimeout(int ms) callTimeout = ms; } - public UniTask Call(string fxName, string data = null, bool ignoreTimeout = false) + public UniTask Call(string fxName, string data = null, bool ignoreTimeout = false, Nullable timeoutMs = null) { var t = new UniTaskCompletionSource(); string requestId = Guid.NewGuid().ToString(); @@ -81,7 +81,7 @@ public UniTask Call(string fxName, string data = null, bool ignoreTimeou if (ignoreTimeout) return t.Task; else - return t.Task.Timeout(TimeSpan.FromMilliseconds(callTimeout)); + return t.Task.Timeout(TimeSpan.FromMilliseconds(timeoutMs ?? callTimeout)); } private void CallFunction(string requestId, string fxName, string data = null) diff --git a/src/Packages/Passport/Runtime/Scripts/Private/PassportImpl.cs b/src/Packages/Passport/Runtime/Scripts/Private/PassportImpl.cs index 45f92e19..1f91d0f7 100644 --- a/src/Packages/Passport/Runtime/Scripts/Private/PassportImpl.cs +++ b/src/Packages/Passport/Runtime/Scripts/Private/PassportImpl.cs @@ -49,7 +49,8 @@ public PassportImpl(IBrowserCommunicationsManager communicationsManager) this.communicationsManager = communicationsManager; } - public async UniTask Init(string clientId, string environment, string redirectUri = null, string logoutRedirectUri = null, string deeplink = null) + public async UniTask Init(string clientId, string environment, string redirectUri = null, + string logoutRedirectUri = null, string deeplink = null) { this.redirectUri = redirectUri; this.logoutRedirectUri = logoutRedirectUri; @@ -242,7 +243,10 @@ private async UniTask InitialiseDeviceCodeAuth(string callingFu }; } - throw new PassportException(deviceConnectResponse?.error ?? $"Something went wrong, please call {callingFunction} again", PassportErrorType.AUTHENTICATION_ERROR); + throw new PassportException( + deviceConnectResponse?.error ?? $"Something went wrong, please call {callingFunction} again", + PassportErrorType.AUTHENTICATION_ERROR + ); } private async UniTask ConfirmCode( @@ -267,12 +271,13 @@ private async UniTask ConfirmCode( string callResponse = await communicationsManager.Call( functionToCall, JsonUtility.ToJson(request), - true // Ignore timeout, this flow can take minutes to complete. 15 minute expiry from Auth0. - ); + ignoreTimeout: timeoutMs == null, + timeoutMs); } else { - throw new PassportException($"Unable to confirm code, call {callingFunction} again", PassportErrorType.AUTHENTICATION_ERROR); + throw new PassportException($"Unable to confirm code, call {callingFunction} again", + PassportErrorType.AUTHENTICATION_ERROR); } } diff --git a/src/Packages/Passport/Runtime/Scripts/Public/Passport.cs b/src/Packages/Passport/Runtime/Scripts/Public/Passport.cs index bf21f8cb..39f5b67a 100644 --- a/src/Packages/Passport/Runtime/Scripts/Public/Passport.cs +++ b/src/Packages/Passport/Runtime/Scripts/Public/Passport.cs @@ -147,6 +147,7 @@ public void SetCallTimeout(int ms) /// /// Logs the user into Passport via device code auth. This will open the user's default browser and take them through Passport login. /// If true, the saved access token or refresh token will be used to log the user in. If this fails, it will not fallback to device code auth. + /// (Optional) The maximum time, in milliseconds, the function is allowed to take before a TimeoutException is thrown. If not set, the function will wait indefinitely. /// public async UniTask Login(bool useCachedSession = false, Nullable timeoutMs = null) { @@ -157,6 +158,7 @@ public async UniTask Login(bool useCachedSession = false, Nullable t /// Logs the user into Passport via device code auth and sets up the IMX provider. This will open the user's /// default browser and take them through Passport login. /// If true, the saved access token or refresh token will be used to connect the user. If this fails, it will not fallback to device code auth. + /// (Optional) The maximum time, in milliseconds, the function is allowed to take before a TimeoutException is thrown. If not set, the function will wait indefinitely. /// public async UniTask ConnectImx(bool useCachedSession = false, Nullable timeoutMs = null) { diff --git a/src/Packages/Passport/Tests/Runtime/Scripts/PassportTests.cs b/src/Packages/Passport/Tests/Runtime/Scripts/PassportTests.cs index c39db933..2409e2a1 100644 --- a/src/Packages/Passport/Tests/Runtime/Scripts/PassportTests.cs +++ b/src/Packages/Passport/Tests/Runtime/Scripts/PassportTests.cs @@ -1130,7 +1130,7 @@ public void AddMockResponse(object response) responses.Enqueue(JsonUtility.ToJson(response)); } - public UniTask Call(string fxName, string data = null, bool ignoreTimeout = false) + public UniTask Call(string fxName, string data = null, bool ignoreTimeout = false, Nullable timeoutMs = null) { if (throwExceptionOnCall) {