question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] AcquireTokenSilent not working after few mintunes in ios and anroid giving error

See original GitHub issue

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

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**

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
viveknegi51288commented, Jun 25, 2020

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

1reaction
bgavrilMScommented, Jun 26, 2020

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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Not getting token with acquireTokensilent but ...
The thing is when i am using acquireTokenSilent its giving error as: getTokenerror BrowserAuthError: no_account_error: No account object ...
Read more >
MsalError Class (Microsoft.Identity.Client)
Error code returned as a property in MsalException. ... the device code expired before the user signed-in on another device (this is usually...
Read more >
Msal acquiretokensilent example. Have you run into this or ...
The following code snippet illustrates token acquisition in an MSAL Node confidential ... but they are still receiving critical security bug fix support....
Read more >
O365 refresh token. Copy the 'Application (client) ID and paste it
This is easy to fix by running the rclone config reconnect remote: command to get a new token and refresh token. Microsoft recently...
Read more >
Clear aad broker cache. It is important to note that forcing ...
We are working to add a fix to clear the cache. Right click on Windows PowerShell on the results and select Run as...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found