Skip to content
This repository has been archived by the owner on Jun 30, 2023. It is now read-only.

AcquireTokenSilent #144

Closed
rlongodev opened this issue Jan 2, 2015 · 3 comments
Closed

AcquireTokenSilent #144

rlongodev opened this issue Jan 2, 2015 · 3 comments

Comments

@rlongodev
Copy link

Hi! I'm having this exception when trying to run the AcquireTokenSilent method on AuthenticationContext class :
AdalSilentTokenAcquisitionException
Message : Failed to acquire token silently. Call method AcquireToken.

I'm following this sample code https://github.com/AzureADSamples/WebApp-WebAPI-OpenIDConnect-DotNet, so the scenario is the same. I searched on the web but every solution I found wasn't the right one. I also took a look at the source code and I found this code in the AcquireTokenSilentHandler class :

protected override Task<AuthenticationResult> SendTokenRequestAsync()
{
    Logger.Verbose(this.CallState, "No token matching arguments found in the cache");
    throw new AdalSilentTokenAcquisitionException();
}

So, is this feature not implemented or I just can't figure out what is going on?

Thanks a lot.

Rodrigo

@vibronet
Copy link
Contributor

vibronet commented Jan 2, 2015

The feature is definitely implemented. Are you executing the example code precisely as is, or did you modify anything in it? Typical issues with AcquireTokenSilent in web scenarios are:

  • The cache is empty. AcquireTokenSilent works by returning cached tokens or using refresh tokens from the cache. In the OpenId Connect samples, the application first acquires access and refresh tokens at sign in time and places them in a cache instance. If something happens to the cache between that time and the time in which you call AcquireTokenSilent, or if you fail to initialize AuthenticationContext with the exact same cache instance, the request will fail.
  • The cache contains more than one token matching the parameters, for example for 2 different users. In that case ADAL needs more info (like the ID of the user you want ta token for) to disambiguate the request
  • You are requesting a token from a new AAD tenant. Refresh tokens in the cache will work for requesting new tokens only from the same tenant they were originally issued from
    You can verify in which situation you are by inspecting the content of the cache before making your AcquireTokenSilent call, simply call myAuthContext.TokenCache.ReadItems and examine the results in the debugger.
    HTH

@rlongodev
Copy link
Author

Hi Vittorio, thanks a lot for the quick response. You are right, I think I misunderstood the samples and my scenario its a little bit different. Thing is I didn't get a token before a call to AcquireTokenSilent.

Regards,
Rodrigo

@kpanwar
Copy link
Contributor

kpanwar commented Apr 25, 2016

If you use the latest 2.24 then you will get an inner exception that will tell you why acquire token silent failed. Can you check and share the details.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants