I have a website where I login via OAuth and AzureAD. I aquire my OAuth AuthenticationToken like this:
Claim tenantClaim = ClaimsPrincipal.Current.FindFirst(TenantIdClaimType);
if (tenantClaim != null)
{
string tenantId = tenantClaim.Value;
string userObjectID = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value;
AuthenticationContext authContext = new AuthenticationContext(Startup.Authority, new NaiveSessionCache(userObjectID));
ClientCredential credential = new ClientCredential(clientId, appKey);
AuthenticationResult authenticationResult = await authContext.AcquireTokenSilentAsync(dynamicsUrl, credential, new UserIdentifier(userObjectID, UserIdentifierType.UniqueId));
return authenticationResult.CreateAuthorizationHeader();
}
It worked well all the time. I lost track of the website for about 3 months and it's not working anymore. I debugged through my code and tried to do it "manually". Went on http://schemas.microsoft.com/identity/claims/tenantid and I saw this message:
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
Is it removed, renamed or something? I checked AzureAD, everything is still valid (not expired) I even created a new appKey and tried it but it's still not working.
I'm sorry for my bad english I hope you guys understand what I'm asking and what I'm talking about. If you need further informations please let me know.
Thank you for taking the time I appreciate your help.
Best regards, Nico aka. Myridor
I found the solution.
It had nothing to do with the Claims, the problem was the NaiveSessionCache because ADAL updated a method so that it starts a new Thread..
Found my answer here: HttpContext.Current is null on TokenCache.BeforeAccess