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.

GetAccountsAsync() does Instance Discovery call...will not work off-line

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:37 (13 by maintainers)

github_iconTop GitHub Comments

2reactions
jmprieurcommented, Nov 8, 2018

@Surfrat : we are looking at what we can do here.

1reaction
Surfratcommented, Nov 26, 2018

@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. image

Android (Nokia 8):

Token details displayed while on and offline. The following screenshot is the same for both.Note the aeroplane mode icon.

screenshot_20181126-092719

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

Read more comments on GitHub >

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

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