microsoft-authentication-library-for-dotnet: GetAccountsAsync() does Instance Discovery call...will not work off-line
name: 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?
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 37 (13 by maintainers)
@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
I can then get user info in the token and use it. This worked in v1.