ADAL Persistent TokenCache in UWP Application
<p>I'm doing simple AAD authentication in a new Windows 10 UWP app. It's working great, except for I don't want the user to enter their credentials each time the app is launched. From what I understand, the default shared TokenCache is supposed to do this automatically, but the authentication dialog pops up the first time I call AcquireTokenAsync after the app is started. </p>

<p>Interestingly, I can call TokenCache.ReadItems() and my TokenCacheItem is there.</p>

<p>My ADAL trace is below. As you can see, a token is deserialized, but it doesn't consider it to be a match for the current user. Thanks!</p>

<pre><code>2016-02-27 18:30:56:8139    Type: Informational Id: 2   Message: '2/28/2016 12:30:56 AM:  - TokenCache.cs: Deserialized 1 items to token cache.'
2016-02-27 18:30:56:8199    Type: Informational Id: 2   Message: '2/28/2016 12:30:56 AM:  - AuthenticationContext.cs: ADAL WinRT with assembly version '2.21.0.0', file version '2.21.30122.1612' and informational version '99c728ed4636738ad0f97ca000a9d88cc5b75cc0' is running...'
2016-02-27 18:30:56:8364    Type: Informational Id: 2   Message: '2/28/2016 12:30:56 AM: 12cc879d-1196-43ef-9e03-389a69dd4432 - AcquireTokenHandlerBase.cs: === Token Acquisition started:
    Authority: https://login.windows.net/common/
    Resource: https://management.core.windows.net/
    ClientId: 486c0900-9582-4672-92af-37013e31958d
    CacheType: Microsoft.IdentityModel.Clients.ActiveDirectory.TokenCache (1 items)
    Authentication Target: User
    '
2016-02-27 18:30:56:8569    Type: Informational Id: 2   Message: '2/28/2016 12:30:56 AM:  - TokenCache.cs: Deserialized 1 items to token cache.'
2016-02-27 18:30:56:8589    Type: Verbose   Id: 1   Message: '2/28/2016 12:30:56 AM: 12cc879d-1196-43ef-9e03-389a69dd4432 - TokenCache.cs: Looking up cache for a token...'
2016-02-27 18:30:56:8679    Type: Informational Id: 2   Message: '2/28/2016 12:30:56 AM: 12cc879d-1196-43ef-9e03-389a69dd4432 - TokenCache.cs: No matching token was found in the cache'
2016-02-27 18:30:56:8989    Type: Informational Id: 2   Message: '2/28/2016 12:30:56 AM: 12cc879d-1196-43ef-9e03-389a69dd4432 - AcquireTokenInteractiveHandler.cs: Cannot access user information to determine whether it is a local user or not due to machine's privacy setting.'
</code></pre>

<p><strong>Update</strong>
Thanks to the link provided by Kanishk, I was able to solve this. I highly recommend reading the full post, but this is what I ended up doing:</p>

<pre><code>_authenticationContext = new AuthenticationContext("https://login.windows.net/common");

var tokenCacheItem = _authenticationContext.TokenCache.ReadItems().FirstOrDefault();
if (tokenCacheItem != null)
{
    _authenticationContext = new AuthenticationContext($"https://login.windows.net/{tokenCacheItem.TenantId}");
}
</code></pre>