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.

AcquireTokenSilentAsync returns "Authority passed to silent parameters does not match with the cloud associated to the account."

See original GitHub issue

I have a working app with a b2c configuration. Up until now I used the legacy b2c policy / authority URL’s: e.g. https://login.microsoftonline.com/tfp/<my-tenant>/B2C_1_SignUpPolicy.

Today I tried to change them to the new URL style: e.g. https://whatever.b2clogin.com/tfp/<my-tenant>/B2C_1_SignUpPolicy/

And suddenly I get the mentioned error from above when calling acquireTokenSilentAsync. I also compared with the sample app (https://github.com/Azure-Samples/ms-identity-android-java/) and couldn’t find a real difference.

I also started investigating myself and dug quite deep and found the exception is thrown here:

public class AcquireTokenSilentOperationParameters extends OperationParameters {
//.... what ever
    @Override
    public void validate() throws ArgumentException {
        super.validate();

        if (mAccount == null) {
            Logger.warn(TAG, "The account set on silent operation parameters is NULL.");
        } else if (!authorityMatchesAccountEnvironment()) {
            throw new ArgumentException(
                    ArgumentException.ACQUIRE_TOKEN_SILENT_OPERATION_NAME,
                    ArgumentException.AUTHORITY_ARGUMENT_NAME,
                    "Authority passed to silent parameters does not match with the cloud associated to the account."
            );
        }
    }

    private boolean authorityMatchesAccountEnvironment() {
        final String methodName = ":authorityMatchesAccountEnvironment";
        try {
            if (!AzureActiveDirectory.isInitialized()) {
                performCloudDiscovery();
            }
            final AzureActiveDirectoryCloud cloud = AzureActiveDirectory.getAzureActiveDirectoryCloudFromHostName(mAccount.getEnvironment());
            return cloud != null && cloud.getPreferredNetworkHostName().equals(getAuthority().getAuthorityURL().getAuthority());
        } catch (IOException e) {
            Logger.error(
                    TAG + methodName,
                    "Unable to perform cloud discovery",
                    e);
            return false;
        }
    }

I debugged into the method final AzureActiveDirectoryCloud cloud = AzureActiveDirectory.getAzureActiveDirectoryCloudFromHostName(mAccount.getEnvironment()); which returns null, because it contains only the following hosts: image

my host (whatever.b2clogin.com) obviously doesn’t match there and therefore null is returned.

However I cannot believe that such a bug exists in this library. So I assume I configured something wrong. However I just can’t point my finger on what it could be.

Here is my configuration:

{
  "client_id": "whatever",
  "redirect_uri": "msalbwhatever://auth",
  "broker_redirect_uri_registered": false,
  "authorities": [
    {
      "type": "B2C",
      "authority_url": "https://whatever.b2clogin.com/tfp/whatever.onmicrosoft.com/B2C_1_SignInSignUpPolicy/",
      "default": true
    },
    {
      "type": "B2C",
      "authority_url": "https://whatever.b2clogin.com/tfp/whatever.onmicrosoft.com/B2C_1_SignUpPolicy/"
    },
    {
      "type": "B2C",
      "authority_url": "https://whatever.b2clogin.com/tfp/whatever.onmicrosoft.com/B2C_1_ResetPasswordPolicy/"
    }
  ],
  "account_mode": "MULTIPLE",
  "logging": {
    "pii_enabled": true,
    "log_level": "VERBOSE",
    "logcat_enabled": true
  }
}

Any help would be greatly appreciated!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:20 (16 by maintainers)

github_iconTop GitHub Comments

2reactions
Nasicuscommented, Jan 8, 2020

Tested this just now and I can confirm it’s now working as expected.

Thanks for the quick fix 👍

1reaction
shahzaibjcommented, Jun 12, 2020

@duyvt88 I’m glad to hear that 😊

Read more comments on GitHub >

github_iconTop Results From Across the Web

AcquireTokenSilentAsync failed_to_acquire_token_silently
The error failed_to_acquire_token_silently occurs when an access token cannot be found in the cache or the access token is expired.
Read more >
Errors and exceptions (MSAL Android) - Microsoft Entra
This exception usually indicates a bug in the sdk for storing tokens or that the authority is not provided in the silent request...
Read more >
SingleAccountPublicClientApplic...
Perform acquire token silent call. If there is a valid access token in the cache, the sdk will return the access token; If...
Read more >
MSAL.PS - PowerShell Gallery
Two accounts are equal when their <see cref="P:Microsoft.Identity.Client.AccountId. ... Should not be used when the authority is not know in advance.
Read more >
Microsoft Authentication Library for JavaScript (MSAL.js)
Please note that consenting to scopes on login, does not return an access_token for these scopes, but gives you the opportunity to obtain...
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