We have a large micro service architecture. All services work with JwtBearer against the Azure AD 1.0 endpoint.
Now we want to access user schema extensions of Azure AD. The recommended way in this case is Microsoft Graph. But we dont want to move all services and auth endpoints to 2.0 right now.
But the problem is, that the token of Azure AD 1.0 is not valid to get an on-behalf-token for Azure AD 2.0:
Microsoft.Identity.Client.MsalUiRequiredException: AADSTS70002: Error validating credentials. AADSTS50013: The token issuer doesn't match the api version: A version 1 token cannot be used with the v2 endpoint
We use this code right know
// create instance to read cca with a user token cache
ConfidentialClientApplication cca =
new ConfidentialClientApplication(_azureOptions.ClientId, _azureOptions.RedirectUri,
new ClientCredential(_azureOptions.ClientSecret),
userTokenCache, null);
// try to get an on behalf token
AuthenticationResult result;
try
{
result = await cca.AcquireTokenOnBehalfOfAsync(
_graphOptions.GetScopesCollection(),
new UserAssertion(accessToken.RawData), _graphOptions.Authority);
}
catch (Exception exc)
{
// ...
throw;
}
In this case _azureOptions
works against Azure AD 1.0 and _graphOptions
against 2.0 (/v2.0 endpoint)
The exceptions happens on AcquireTokenOnBehalfOfAsync
Thanks, Ben
_graphOptions.Authority
from 2.0 to 1.0 – Benjamin Abt