2

In mobile app, I have written ADAL authentication logic which is working for most of the users.

var authContext = new AuthenticationContext(authority);
var controller = 
UIApplication.SharedApplication.KeyWindow.RootViewController;
var uri = new Uri(returnUri);
var platformParams = new PlatformParameters(controller);
var authResult = await authContext.AcquireTokenAsync(resource, clientId, 
uri, platformParams);

Only 2-3 odd users are getting below exception.

{Microsoft.IdentityModel.Clients.ActiveDirectory.AdalException: multiple_matching_tokens_detected: The cache contains multiple tokens satisfying the requirements. Call AcquireToken again providing more arguments (e.g. UserId) at Microsoft.IdentityModel.Client…}

What is the root cause of this issue ? Why it is coming for only few users? How to solve this?

San9211
  • 191
  • 1
  • 12
  • Does this answer your question? [multiple\_matching\_tokens\_detected with ADAL](https://stackoverflow.com/questions/32000185/multiple-matching-tokens-detected-with-adal) – lesyk Sep 02 '20 at 07:25

1 Answers1

1

This means that per a given tuple of authority/clientID/resource, ADAL's cache has more than one token matching those values. That typically happens when you acquire tokens using multiple accounts, which leads with multiple entries- all with the same authority/clientID/resource but different user identifiers. If your app is meant to support multiple accounts at once, you need to call the overload of AcquireTokenAsync that requests a userID as well, so that you can eliminate the ambiguity. If your app is meant to be single user, then you need to understand how you ended up with multiple users. I recommend revisiting the flow thoruhg which users enter account information in your app, and flag the steps where they can use different accounts. You can help users by passing your intended account identifier in AcquireTokenAsync- that will prepopulate the UX with the correct account name.

vibronet
  • 7,364
  • 2
  • 19
  • 21