We use Azure Active Directory to secure our Azure hosted APIs. These APIs are consumed by Azure hosted Angular applications. Mocst of the APIs are implemented as an ASP.NET WebAPI, some of them are now implemented using Azure Functions.
We've been securing our applications this way for the past couple of years and haven't had any issues. We were already granting access to one application based on tokens for the other by adding them to the allowed audiences, which was working fine. Currently, we're running into an issue while implementing a new scenario.
The issue
We have two applications: the current application (cur) and the targeted application (tar). All of our users can login to cur. The backend for cur gets a token to access tar based on the token the user got for cur. This works for users that are backed by an Azure Active Directory, either ours or a federated one. As soon as users log in that are not backed by an Azure Active Directory (which means they are backed by a Microsoft account), getting the token for tar fails with a AADSTS50000: There was an error issuing a token.
Context
Our applications are hosted in a different AAD tenant than where our users and applications are registered. The users and app registrations are in the same AAD tenant. We don't think this is an issue, since the configuration is working for AAD backed accounts.
We're using AuthenticationContext.AcquireTokenAsync(String, ClientCredential, UserAssertion) to get a token to access tar with the following parameters:
- ID of tar application
- ID and Key of cur
- Token of the current user for cur
We're seeing one major difference between the original tokens for AAD backed accounts and Microsoft account backed accounts: the IDP (IdentityProvider) field is different. For Microsoft account backed accounts, the IDP is live.com. For AAD backed accounts, this is https://sts.windows.net/<guid>.
We've created several test accounts, both in our AAD and external ones, to make sure it's not an issue related to our existing user accounts. Using different configurations for our AuthenticationContext or ClientCredential does not solve the issue.
Any ideas?