GetAccountsAsync() does Instance Discovery call...will not work off-line
See original GitHub issuename: Bug report about: Pca.GetAccountsAsync() does not work offline
Which Version of MSAL are you using ? MSAL 2.2.0-preview (Latest)
Which platform has the issue? UWP, Xamarin android, . Cannot test iOS due to this issue with PCA and iOS simulator.
What authentication flow has the issue?
- Desktop
- Interactive
- WIA
- U/P
- Device code flow (browserless)
- Mobile
- Web App
- Authorization code
- OBO
- Web API
- OBO
Other? - please describe;
Repro v1.x works offline. This line in v2.x:
IEnumerable<IAccount> accounts = await Pca.GetAccountsAsync();
throws
$exception | {System.Net.Http.HttpRequestException: An error occurred while sending the request. —>
Expected behavior Needs to return the tokens already in the cache
Actual behavior Exception thrown, show is over.
Additional context/ Logs / Screenshots
Here is my code:
public async Task<AuthenticationResult> AcquireTokenForSignInSilentlyAsync()
{
AuthenticationResult authenticationResult = null;
try
{
IEnumerable<IAccount> accounts = await Pca.GetAccountsAsync();
authenticationResult =
await Pca.AcquireTokenSilentAsync(_scopes, GetAccountByPolicy(accounts, _policySignUpSignIn));
}
catch (Exception e)
{
//Do nothing as will force a login.
}
return authenticationResult;
}
private IAccount GetAccountByPolicy(IEnumerable<IAccount> accounts, string policy)
{
IAccount foundAccount = null;
foreach (IAccount account in accounts)
{
string userIdentifier = account.HomeAccountId.Identifier.Split('.')[0];
if (userIdentifier.EndsWith(policy.ToLower()))
{
foundAccount = account;
break;
}
}
return foundAccount;
}
What am I missing?
Issue Analytics
- State:
- Created 5 years ago
- Comments:37 (13 by maintainers)
Top Results From Across the Web
PublicClientApplication - GetAccountsAsync() doesn't ...
I'm developing a little WPF-App that is supposed to query some data from the MS Graph API. I want to use SSO, so...
Read more >ClientApplicationBase.GetAccountsAsync Method
This is for Azure AD B2C scenarios. GetAccountsAsync(). Returns all the available accounts in the user token cache for the application. GetAccountsAsync(String, ...
Read more >ASP.NET Framework MSGraph empty GetAccountsAsync()
When you call GetAccountsAsync for the first time or if you the token cache is empty it can return empty accounts collection. In...
Read more >Integrate Paylocity - Azure Active Directory forum
Hi. We have some serious issues with the Azure Active Directory Connect installed on one of our domain controllers. The program seemed corrupt...
Read more >Security Aspects of Software Development in the Microsoft ...
Examine security aspects of software development on the Microsoft Azure platform. Identify and review important services that the developers ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Surfrat : we are looking at what we can do here.
@jmprieur I dug out my old test project using MSAL v1.1.4.preview. It is attached.
Offline is aeroplane mode with no internet connection. The results are as follows:
UWP: Token details displayed while on and offline. The following screenshot is the same for both.
Android (Nokia 8):
Token details displayed while on and offline. The following screenshot is the same for both.Note the aeroplane mode icon.
iOS Simulator.
There is a known problem in that the simulator does not remember the token. I did test it on a device and it worked offline when I last ran this project.
Attached is my test project. I have removed my ID’s (I tested with mine) but yours are still there.
active-directory-b2c-MF.zip