Microsoft-authentication-library-for-dotnet: [Bug] AcquireTokenSilent not working after few mintunes in ios and anroid giving error

Created on 17 Jun 2020  路  13Comments  路  Source: AzureAD/microsoft-authentication-library-for-dotnet

Which Version of MSAL are you using ?

MSAL 4.14.0

Platform
Xamarin forms (Android and IOS)

What authentication flow has the issue?

  • Mobile

    • [ this] Interactive

    • [ ] Integrated Windows Auth

    • [ ] Username Password

    • [ ] Device code flow (browserless)

Other? - please describe;

Is this a new or existing app?
c. This is a new app or experiment

Repro

```csharp
Initially, application opening a login page, after entering the credentials, I am able to receive the token. Once application closed and suddenly open its getting token sliently by using below method:
authResult = await App.PCA.AcquireTokenSilent(App.Scopes, firstAccount).ExecuteAsync();

But after 15-20 min , when trying to open the application its again prompting for login screen.
Please help.

Android : - Android behaving weird,AcquireTokenSilent sometimes getting proper result, but sometime getting "Broker response returned error: Failed to acquire token sliently from the broker. IN order to perform brokered authentication on android you need to ensure that you have installed either Intune company portal(5.0.4789.0 or greater) or Microsoft Authenticator (6.2001.01400 or greater).

But I have already installed both above application.

PLEASE HELP

Expected behavior
IOS - Should not prompt for login screen after any mintues as already entered credentials once.
Android - Should not give any error as company portal and microsoft authenticator app already installed in the device.

Actual behavior
IOS - After few mins its asking for login with credentials
ANdorid - Anytime giving this error "Broker response returned error: Failed to acquire token sliently from the broker. IN order to perform brokered authentication on android you need to ensure that you have installed either Intune company portal(5.0.4789.0 or greater) or Microsoft Authenticator (6.2001.01400 or greater).

Possible Solution
NO solution. Please help me

Additional context/ Logs / Screenshots

Investigate bug

All 13 comments

any update ?

Hi @viveknegi51288 - we just released MSAL 4.15 where we've re-tested all the mobile scenarios and it all seems to work fine.

Can you try with MSAL 4.15 and if you still encounter the problem, can you enabled logging and post the logs so we can investigate please ?

https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/wiki/logging

HI @bgavrilMS , the behavior is still same, i tried with below code with (withForceRefresh(true) and with (WithForceRefresh(false)but application after few minutes prompting for login screen.

IEnumerable accounts = await App.PCA.GetAccountsAsync();

                    IAccount firstAccount = accounts.FirstOrDefault();
                    authResult = await App.PCA.AcquireTokenSilent(App.Scopes, firstAccount).WithAuthority(StringConstants.MFA_URL).WithForceRefresh(true).ExecuteAsync();

LOGS. : -

warning HE0030: Could not mount developer tools on 'vivek???s iPhone': Could not locate device support files.
warning HE0031: Failed to mount developer tools on 'vivek???s iPhone'.
2020-06-22 15:37:11.210 mlaunch[19766:124725] Thread Pool Worker DTDKRemoteDeviceConnection: Failed to start Instruments daemon on device ???455d114110519cadf3792f825b44fc7a3a2c8b21???: Error Domain=com.apple.dtdevicekit Code=-402653150 "An error was encountered while attempting to communicate with this device. (The service is invalid.)" UserInfo={NSLocalizedFailureReason=Please try rebooting and reconnecting the device. (0xE8000022)., com.apple.dtdevicekit.stacktrace=(
0 DTDeviceKitBase 0x000000010b24a6e7 DTDKCreateNSError + 109
1 DTDeviceKitBase 0x000000010b24ade9 DTDK_AMDErrorToNSError + 792
2 DTDeviceKitBase 0x000000010b25bd0c __63-[DTDKRemoteDeviceConnection startFirstServiceOf:unlockKeybag:]_block_invoke + 301
3 DTDeviceKitBase 0x000000010b25b4db __48-[DTDKRemoteDeviceConnection futureWithSession:]_block_invoke_3 + 22
4 DTDeviceKitBase 0x000000010b24d15f __DTDKExecuteInSession_block_invoke_2 + 35
5 DTDeviceKitBase 0x000000010b24c593 __DTDKExecuteWithConnection_block_invoke_2 + 473
6 DTDeviceKitBase 0x000000010b24c391 __DTDKExecuteWithConnection_block_invoke + 106
7 libdispatch.dylib 0x00007fff71ab763d _dispatch_client_callout + 8
8 libdispatch.dylib 0x00007fff71ac3478 _dispatch_sync_invoke_and_complete_recurse + 65
9 libdispatch.dylib 0x00007fff71ac2fe6 _dispatch_sync_f_slow + 195
10 DVTFoundation 0x000000010a733650 DVTDispatchBarrierSync + 208
11 DVTFoundation 0x000000010a70aa78 -[DVTDispatchLock performLockedBlock:] + 64
12 DTDeviceKitBase 0x000000010b24c292 DTDKExecuteWithConnection + 226
13 DTDeviceKitBase 0x000000010b24cfc9 DTDKExecuteInSession + 376
14 DTDeviceKitBase 0x000000010b25b410 __48-[DTDKRemoteDeviceConnection futureWithSession:]_block_invoke_2 + 112
15 DVTFoundation 0x000000010a7313ba __DVT_CALLING_CLIENT_BLOCK__ + 7
16 DVTFoundation 0x000000010a732a92 __DVTDispatchAsync_block_invoke + 809
17 libdispatch.dylib 0x00007fff71ab65f8 _dispatch_call_block_and_release + 12
18 libdispatch.dylib 0x00007fff71ab763d _dispatch_client_callout + 8
19 libdispatch.dylib 0x00007fff71abd8e0 _dispatch_lane_serial_drain + 602
20 libdispatch.dylib 0x00007fff71abe396 _dispatch_lane_invoke + 385
21 libdispatch.dylib 0x00007fff71ac66ed _dispatch_workloop_worker_thread + 598
22 libsystem_pthread.dylib 0x00007fff71cf7611 _pthread_wqthread + 421
23 libsystem_pthread.dylib 0x00007fff71cf73fd start_wqthread + 13
), DVTRadarComponentKey=487927, NSLocalizedDescription=An error was encountered while attempting to communicate with this device. (The service is invalid.)}
warning MT1043: Failed to launch the application using the instruments service. Will try launching the app using gdb service.
Launching 'com.enbd.hrapp' on the device 'vivek???s iPhone'
warning HE0030: Could not mount developer tools on 'vivek???s iPhone': Could not locate device support files.
warning HE0031: Failed to mount developer tools on 'vivek???s iPhone'.
warning HE0030: Could not mount developer tools on 'vivek???s iPhone': Could not locate device support files.
warning HE0031: Failed to mount developer tools on 'vivek???s iPhone'.
error MT1007: Failed to launch the application '/Users/vivek/Documents/Staff APP/HR-App/HRAPPPOC.iOS/bin/iPhone/Debug/device-builds/iphone10.4-13.4.1/HRAPPPOC.iOS.app' on the device 'vivek???s iPhone': Failed to launch the application 'com.enbd.hrapp' on the device 'vivek???s iPhone': Invalid Service Error (error: 0xe8000022). You can still launch the application manually by tapping on it.
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/Mono.Security.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/System.Core.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/System.Numerics.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/System.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/System.Net.Http.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/System.Drawing.Common.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/Xamarin.iOS.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/System.Xml.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/Xamarin.Forms.Platform.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/Xamarin.Forms.Core.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/System.ServiceModel.Internals.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/System.Runtime.Serialization.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/Xamarin.Forms.Platform.iOS.dll [External]
Thread started: #2
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/System.Xml.Linq.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/Microsoft.CSharp.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/Microsoft.Identity.Client.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/ImageCircle.Forms.Plugin.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/Lottie.iOS.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/Lottie.Forms.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/Xamarin.Essentials.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/Microsoft.AppCenter.iOS.Bindings.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/Microsoft.AppCenter.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/Microsoft.AppCenter.Analytics.iOS.Bindings.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/Microsoft.AppCenter.Crashes.iOS.Bindings.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/Microsoft.AppCenter.Crashes.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/HtmlLabel.Forms.Plugin.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/EasyTipView.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/Microsoft.Intune.MAM.iOS.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/UltimateXF.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/iOSCharts.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/UltimateXF.iOS.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/Rg.Plugins.Popup.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/Rg.Plugins.Popup.IOS.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/PanCardView.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/PanCardView.iOS.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/System.Data.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/Newtonsoft.Json.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/Prism.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/Prism.Forms.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/Xamarin.Forms.Xaml.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/Xamarin.Forms.Skeleton.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/Plugin.Connectivity.Abstractions.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/Unity.Abstractions.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/Unity.Container.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/Prism.Unity.Forms.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/Microsoft.AppCenter.Analytics.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/Plugin.Connectivity.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/HRAPPPOC.dll
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/HRAPPPOC.iOS.exe
Loaded assembly: /private/var/containers/Bundle/Application/D427FB44-9732-4C4E-B5F2-1CA1D3DCA7C3/HRAPPPOC.iOS.app/OpenTK-1.0.dll [External]
Thread started: #3
Thread started: #4
Thread started: #5
Thread started: #6
Thread started: #7
Thread started: #8
Thread started: #9
Resolved pending breakpoint at 'DashboardPageViewModel.cs:206,1' to void HRAPPPOC.ViewModels.DashboardPageViewModel.d__78.MoveNext () [0x0023a].
Resolved pending breakpoint at 'DashboardPageViewModel.cs:222,1' to void HRAPPPOC.ViewModels.DashboardPageViewModel.d__78.MoveNext () [0x003a4].
Resolved pending breakpoint at 'DashboardPageViewModel.cs:224,1' to void HRAPPPOC.ViewModels.DashboardPageViewModel.d__78.MoveNext () [0x003af].
Resolved pending breakpoint at 'DashboardPageViewModel.cs:204,1' to void HRAPPPOC.ViewModels.DashboardPageViewModel.d__78.MoveNext () [0x0021c].
Resolved pending breakpoint at 'DashboardPageViewModel.cs:195,1' to void HRAPPPOC.ViewModels.DashboardPageViewModel.d__78.MoveNext () [0x000e2].
Resolved pending breakpoint at 'DashboardPageViewModel.cs:227,1' to void HRAPPPOC.ViewModels.DashboardPageViewModel.d__78.MoveNext () [0x003da].
Resolved pending breakpoint at 'DashboardPageViewModel.cs:199,1' to void HRAPPPOC.ViewModels.DashboardPageViewModel.d__78.MoveNext () [0x001b5].
Resolved pending breakpoint at 'DashboardPageViewModel.cs:196,1' to void HRAPPPOC.ViewModels.DashboardPageViewModel.d__78.MoveNext () [0x000f3].
Resolved pending breakpoint at 'DashboardPageViewModel.cs:197,1' to void HRAPPPOC.ViewModels.DashboardPageViewModel.d__78.MoveNext () [0x00193].
Thread started: #10
2020-06-22 15:37:24.062 HRAPPPOC.iOS[700:4711388] Info (False) MSAL 4.15.0.0 MSAL.Xamarin.iOS 13.4.1 [06/22/2020 11:37:24 - e5fa0ce4-eedd-48b0-be44-97940d3a05c8] MSAL MSAL.Xamarin.iOS with assembly version '4.15.0.0'. CorrelationId(e5fa0ce4-eedd-48b0-be44-97940d3a05c8)
2020-06-22 15:37:24.065 HRAPPPOC.iOS[700:4711388] Info (False) MSAL 4.15.0.0 MSAL.Xamarin.iOS 13.4.1 [06/22/2020 11:37:24 - e5fa0ce4-eedd-48b0-be44-97940d3a05c8] === AcquireTokenSilent Parameters ===
2020-06-22 15:37:24.065 HRAPPPOC.iOS[700:4711388] Info (False) MSAL 4.15.0.0 MSAL.Xamarin.iOS 13.4.1 [06/22/2020 11:37:24 - e5fa0ce4-eedd-48b0-be44-97940d3a05c8] LoginHint provided: False
2020-06-22 15:37:24.066 HRAPPPOC.iOS[700:4711388] Info (True) MSAL 4.15.0.0 MSAL.Xamarin.iOS 13.4.1 [06/22/2020 11:37:24 - e5fa0ce4-eedd-48b0-be44-97940d3a05c8] Account provided: Account username: [email protected] environment login.microsoftonline.com home account id: AccountId: a24749c5-d73b-446b-94d9-5bee515b8002.cf29f564-2303-4bfb-a13c-29ef0689ffb9
2020-06-22 15:37:24.066 HRAPPPOC.iOS[700:4711388] Info (False) MSAL 4.15.0.0 MSAL.Xamarin.iOS 13.4.1 [06/22/2020 11:37:24 - e5fa0ce4-eedd-48b0-be44-97940d3a05c8] ForceRefresh: True
2020-06-22 15:37:24.072 HRAPPPOC.iOS[700:4711388] Info (True) MSAL 4.15.0.0 MSAL.Xamarin.iOS 13.4.1 [06/22/2020 11:37:24 - e5fa0ce4-eedd-48b0-be44-97940d3a05c8]
=== Request Data ===
Authority Provided? - True
Client Id - 6a329bfe-9df6-4a17-bf1a-46c2a28c2719
Scopes - api://1ac00bcc-39a7-4680-90e8-16458513859b/access_as_user
Redirect Uri - msauth.com.enbd.hrapp://auth
Extra Query Params Keys (space separated) -
ClaimsAndClientCapabilities -
2020-06-22 15:37:24.073 HRAPPPOC.iOS[700:4711388]
2020-06-22 15:37:24.073 HRAPPPOC.iOS[700:4711388] Info (True) MSAL 4.15.0.0 MSAL.Xamarin.iOS 13.4.1 [06/22/2020 11:37:24 - id] === Token Acquisition (SilentRequest) started:
Authority: "url"
Scope: "scope"
ClientId: "clientid"

2020-06-22 15:37:24.074 HRAPPPOC.iOS[700:4711388] Info (False) MSAL 4.15.0.0 MSAL.Xamarin.iOS 13.4.1 [06/22/2020 11:37:24 - e5fa0ce4-eedd-48b0-be44-97940d3a05c8] Attempting to acquire token using using local cache...
2020-06-22 15:37:24.074 HRAPPPOC.iOS[700:4711388] Info (False) MSAL 4.15.0.0 MSAL.Xamarin.iOS 13.4.1 [06/22/2020 11:37:24 - e5fa0ce4-eedd-48b0-be44-97940d3a05c8] Skipped looking for an Access Token because ForceRefresh or Claims were set
2020-06-22 15:37:24.086 HRAPPPOC.iOS[700:4711388] Info (False) MSAL 4.15.0.0 MSAL.Xamarin.iOS 13.4.1 [06/22/2020 11:37:24 - e5fa0ce4-eedd-48b0-be44-97940d3a05c8] Refresh token found in the cache? - True
2020-06-22 15:37:24.089 HRAPPPOC.iOS[700:4711388] Info (True) MSAL 4.15.0.0 MSAL.Xamarin.iOS 13.4.1 [06/22/2020 11:37:24 - e5fa0ce4-eedd-48b0-be44-97940d3a05c8] Fetching instance discovery from the network from host login.microsoftonline.com. Endpoint https://login.microsoftonline.com/common/discovery/instance
Thread started: #11
Thread started: #12
Thread started: #13
Thread started: #14
Thread started: #15
2020-06-22 15:37:24.974 HRAPPPOC.iOS[700:4711448] Info (False) MSAL 4.15.0.0 MSAL.Xamarin.iOS 13.4.1 [06/22/2020 11:37:24 - e5fa0ce4-eedd-48b0-be44-97940d3a05c8] Resolving authority endpoints... Already resolved? - FALSE
2020-06-22 15:37:25.544 HRAPPPOC.iOS[700:4711460] Info (False) MSAL 4.15.0.0 MSAL.Xamarin.iOS 13.4.1 [06/22/2020 11:37:25 - e5fa0ce4-eedd-48b0-be44-97940d3a05c8] Checking client info returned from the server..
2020-06-22 15:37:25.549 HRAPPPOC.iOS[700:4711460] Info (False) MSAL 4.15.0.0 MSAL.Xamarin.iOS 13.4.1 [06/22/2020 11:37:25 - e5fa0ce4-eedd-48b0-be44-97940d3a05c8] Saving Token Response to cache..
2020-06-22 15:37:25.550 HRAPPPOC.iOS[700:4711460] Info (False) MSAL 4.15.0.0 MSAL.Xamarin.iOS 13.4.1 [06/22/2020 11:37:25 - e5fa0ce4-eedd-48b0-be44-97940d3a05c8] Subject not present in Id token
2020-06-22 15:37:25.552 HRAPPPOC.iOS[700:4711460] Info (False) MSAL 4.15.0.0 MSAL.Xamarin.iOS 13.4.1 [06/22/2020 11:37:25 - e5fa0ce4-eedd-48b0-be44-97940d3a05c8] Saving AT in cache and removing overlapping ATs...
2020-06-22 15:37:25.552 HRAPPPOC.iOS[700:4711460] Info (False) MSAL 4.15.0.0 MSAL.Xamarin.iOS 13.4.1 [06/22/2020 11:37:25 - e5fa0ce4-eedd-48b0-be44-97940d3a05c8] Looking for scopes for the authority in the cache which intersect with api://1ac00bcc-39a7-4680-90e8-16458513859b/access_as_user
2020-06-22 15:37:25.560 HRAPPPOC.iOS[700:4711460] Info (False) MSAL 4.15.0.0 MSAL.Xamarin.iOS 13.4.1 [06/22/2020 11:37:25 - e5fa0ce4-eedd-48b0-be44-97940d3a05c8] Intersecting scope entries count - 1
2020-06-22 15:37:25.560 HRAPPPOC.iOS[700:4711460] Info (False) MSAL 4.15.0.0 MSAL.Xamarin.iOS 13.4.1 [06/22/2020 11:37:25 - e5fa0ce4-eedd-48b0-be44-97940d3a05c8] Matching entries after filtering by user - 1
2020-06-22 15:37:25.586 HRAPPPOC.iOS[700:4711460] Info (False) MSAL 4.15.0.0 MSAL.Xamarin.iOS 13.4.1 [06/22/2020 11:37:25 - e5fa0ce4-eedd-48b0-be44-97940d3a05c8] Saving Id Token and Account in cache ...
2020-06-22 15:37:25.603 HRAPPPOC.iOS[700:4711460] Info (False) MSAL 4.15.0.0 MSAL.Xamarin.iOS 13.4.1 [06/22/2020 11:37:25 - e5fa0ce4-eedd-48b0-be44-97940d3a05c8] Saving RT in cache...
2020-06-22 15:37:25.609 HRAPPPOC.iOS[700:4711460] Info (False) MSAL 4.15.0.0 MSAL.Xamarin.iOS 13.4.1 [06/22/2020 11:37:25] Serializing token cache with 1 items.
2020-06-22 15:37:25.621 HRAPPPOC.iOS[700:4711460] Warning (True) MSAL 4.15.0.0 MSAL.Xamarin.iOS 13.4.1 [06/22/2020 11:37:25] Failed to remove adal cache record: MissingEntitlement
2020-06-22 15:37:25.622 HRAPPPOC.iOS[700:4711460] Warning (True) MSAL 4.15.0.0 MSAL.Xamarin.iOS 13.4.1 [06/22/2020 11:37:25] Failed to save adal cache record: MissingEntitlement
2020-06-22 15:37:25.623 HRAPPPOC.iOS[700:4711460] Info (False) MSAL 4.15.0.0 MSAL.Xamarin.iOS 13.4.1 [06/22/2020 11:37:25 - e5fa0ce4-eedd-48b0-be44-97940d3a05c8] === Token Acquisition finished successfully. An access token was returned with Expiration Time: 06/22/2020 12:37:24 +00:00 ===
Thread finished: #8
2020-06-22 15:37:45.932 HRAPPPOC.iOS[700:4711388] Azure token eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6IlNzWnNCTmhaY0YzUTlTNHRycFFCVEJ5TlJSSSIsImtpZCI6IlNzWnNCTmhaY0YzUTlTNHRycFFCVEJ5TlJSSSJ9.eyJhdWQiOiJhcGk6Ly8xYWMwMGJjYy0zOWE3LTQ2ODAtOTBlOC0xNjQ1ODUxMzg1OWIiLCJpc3MiOiJodHRwczovL3N0cy53aW5kb3dzLm5ldC9jZjI5ZjU2NC0yMzAzLTRiZmItYTEzYy0yOWVmMDY4OWZmYjkvIiwiaWF0IjoxNTkyODI1NTQ1LCJuYmYiOjE1OTI4MjU1NDUsImV4cCI6MTU5MjgyOTQ0NSwiYWNyIjoiMSIsImFpbyI6IkFWUUFxLzhQQUFBQU5OL093T1FUTzlwVk5Xb1psb0pxOXZZbGhFTEk3U0FKS20vZVFxZXRWblVheEN6a3pHelg2QmE0MkE1Q0I5dHZscGZ2R2UrVVlQOHA2VnZkYVhIcVF1UE9YZlFHclRwK1piWFFZL0VRMThBPSIsImFtciI6WyJwd2QiLCJtZmEiXSwiYXBwaWQiOiI2YTMyOWJmZS05ZGY2LTRhMTctYmYxYS00NmMyYTI4YzI3MTkiLCJhcHBpZGFjciI6IjAiLCJmYW1pbHlfbmFtZSI6Ik5lZ2kiLCJnaXZlbl9uYW1lIjoiVml2ZWsiLCJpcGFkZHIiOiI1LjMwLjEzOC4yMyIsIm5hbWUiOiJJVCAoVml2ZWsgTmVnaSkiLCJvaWQiOiJhMjQ3NDljNS1kNzNiLTQ0NmItOTRkOS01YmVlNTE1YjgwMDIiLCJvbnByZW1fc2lkIjoiUy0xLTUtMjEtMTAwOTI5NDU4LTE5NTUwNTM4OS0yNDYyMzkwNTQtMzI5MjI4IiwicmgiOiIwLkFURUFaUFVwendNai0wdWhQQ252Qm9uX3VmNmJNbXIyblJkS3Z4cEd3cUtNSnhreEFIWS4iLCJzY3AiOiJhY2Nlc3NfYXNfdXNlciIsInN1YiI6InJFLWdydThNUGwyUXJndnhtSG1iOUd4TG1Eb1cwR2tmRUExZTBzdnFHTEkiLCJ0aWQiOiJjZjI5ZjU2NC0yMzAzLTRiZmItYTEzYy0yOWVmMDY4OWZmYjkiLCJ1bmlxdWVfbmFtZSI6IlZpdmVrTkVHQGVtaXJhdGVzbmJkLmNvbSIsInVwbiI6IlZpdmVrTkVHQGVtaXJhdGVzbmJkLmNvbSIsInV0aSI6IlZscGRJM1ZfalU2Z1l3SFRtY2VmQUEiLCJ2ZXIiOiIxLjAifQ.giRziDr06Wkzs-JKZRlIU_Kb1XZGXzKPbhrKtTDkKlMW3FwILdstBBQ8cAt-eCi-rCigoAfxipbo4l4xPFus-1ZPPjyrw9d_v5j8C3FM7knUKXcyfb59ZG26k5EH0r0EdNHP8WyxmX8fioaM2ShKb97bjUKle2Dz-IH0xwaFv5qL9G5odjlGekAZ1i8JvlVgnlD2oblu1aRvHxp8o9Y0RFfsJ8Voe5_xKOl3icxagk_T_hwR4zicfLdvozhn0jav7pFOZRRuu3PAoVF6Je_11W_dBB3xSvcVwt2WhZrs6hW0_0XFXsBuORpvTWznHzyKHGKSYohrfnefjV1AC4v0Iw
2020-06-22 15:37:45.934 HRAPPPOC.iOS[700:4711388] Account reg
Thread started: #16
Thread started: #17
2020-06-22 15:37:51.562 HRAPPPOC.iOS[700:4711388] Unbalanced calls to begin/end appearance transitions for .
Current file index 0

@viveknegi51288 - the logs above show are for a successful AcquireTokenSilent with ForceRefresh=true. Note that ForceRefresh will force MSAL to acquire a new access token, even if a valid access token exists in MSAL's cache, so we do not recommend it.

You do not seem to be using the broker (Authenticator)? For Authenticator use, you need to add .WithBroker(true) on the public client application builder object.

Still, the silent token acquisition seems to have worked fine using the system browser. So maybe you did not capture logs for when the problems happens or I do not understand the issue? You say that "after a few minutes it's asking me for credentials..." - who is asking you? I would only expect MSAL to pop-up the browser to ask for credentials and you have control over that.

@bgavrilMS var builder = PublicClientApplicationBuilder.Create(App.ClientID);
builder.WithBroker();
switch (Device.RuntimePlatform)
{
case Device.Android:
builder = builder.WithRedirectUri(App.BrokerRedirectUriOnAndroid).WithLogging(Log, LogLevel.Info, true);
break;
case Device.iOS:
builder = builder.WithIosKeychainSecurityGroup("com.microsoft.adalcache");
builder = builder.WithRedirectUri(App.BrokerRedirectUriOnIos).WithLogging(Log, LogLevel.Info, true); ;
break;
}
App.PCA = builder.Build();

I am using withbroker only, and even when I am using withForceRefresh(false), MSAL pop-up the browser to ask the credentials, as per my understanding once the user enter the credentials it always take token silently and should not ask for credentials.

await App.PCA.AcquireTokenSilent(App.Scopes, firstAccount).WithAuthority(StringConstants.MFA_URL).WithForceRefresh(true).ExecuteAsync();

Could you please help me to understand is there any time limit of AcquireTokenSilent() method,

Requirement - My requirement once the user enter the credentials , so whenever the user will open the application , MSAL should not open the browser ever.

Note : I am not removing any account as there is no logout button in my app. Please @bgavrilMS help

So I opened my application after 1 hour and again its giving below error
AADSTS50076: Due to a configuration change made by your administrator, or because you moved to a new location, you must use multi-factor authentication to access 'id'

I am not seeing any broker usage in the logs. Can you please try to set the LogLevel to Verbose and capture logs again? Also, please do not paste the actual access token on GitHub, it is public - maybe you want to delete the access token or send the logs via email (bogavril at microsoft com). Note that these are you app logs, MSAL never logs tokens.

Your requirement is fine and MSAL should be able to silently get you tokens using AcquireTokenSilent in most cases. Now, if your tenant admin makes config changes, or if you move to a different location etc., then you will need to re-login interactively, like that error explains. MSAL should throw an MsalUiRequiredException in this case.

Thank you so much @bgavrilMS , I have now did some changes in the code and info.plist and now my application trying to get token from authenticator app.

If possible then can you please help me on one more thing, I have implemented Intune sdk also in our app which is working fine in IOS build but getting error on android.

Could you just tell me how to implement IMAMServiceAuthenticationCallback in android using MSAL library.

As per microsoft official documentation,only ADAL implementation with android Intune sdk is defined there. Can you please help me to understand how to use IMAMServiceAuthenticationCallback with MSAL library

Can you point me to the docs around IMAMServiceAuthenticationCallback and how to implement it with ADAL?

Please check in below link
https://docs.microsoft.com/en-us/mem/intune/developer/app-sdk-android#app-protection-policy-without-device-enrollment

Implementation you can see in the Intune sample app for xamarin forms (https://github.com/msintuneappsdk/Taskr-Sample-Intune-Android-App)

If the callback signature is

public string acquireToken(String upn, String aadId, String resourceId) then I would implement it as

var pca = PublicClientApplicationBuilder.Create(<client_id>).Build();
var accounts = await pca.GetAccountsAsync();
var account = accounts.Where(a => a.Username == upn); 
string scope = resourceId + "/user_impersonation"; // if this doesn't work try + "/.default"
var result = await pca.AcquireTokenSilent(account, new[] { scope }).ExecuteAsync();
return result.AccessToken;

Something like that. Not sure what the aadId is though, is it the client id? Or a tenant ID?

Let's open another issue for MAM integration if required. I think the original problem has been resolved.

Thanks @bgavrilMS You helped a lot.... and issue is resolved now. Thanks

Was this page helpful?
0 / 5 - 0 ratings