We have a user managed identity that is used by a Service Fabric Cluster to authenticate to various resources from the services deployed to the cluster. One of the use cases is to request access tokens to an API that we also own and protect with an AAD Application Registration, using the following code snip, where the ResourceId parameter is the AAD Application Registration Client ID:
AppAuthenticationResult tokenResult;
try
{
tokenResult = await this.azureServiceTokenProvider.GetAuthenticationResultAsync(resourceId).ConfigureAwait(false);
}
This has worked fine, however we recently needed to disable guest access to the AAD Application Registration by turning ON the User Assignment Required property on the associated Enterprise Application. Doing this caused the above token requests to fail with the exception:
Tried to get token using Managed Service Identity. Access token could not be acquired. Received a non-retryable error. MSI ResponseCode: BadRequest, Response: {"error":"invalid_grant","error_description":"AADSTS501051Application '<Managed Identity Client ID GUID>'() is not assigned to a role for the application '<AAD Application Registration Client ID GUID>'
We have dug through the documentation, but can't seem to find how to assign a application role to the AAD Application from the Managed Identity. How is this intended to be accomplished?