

и UMI также был добавлен в качестве пользователя приложения в среде Power Platform

Но при запуске моего кода я сталкиваюсь со следующей ошибкой при вызове метода со следующими параметрами:
ClientId = 6e32e0d6-bd02-4c0f -930c-eecbab684758
DataverseUrl = https://msys-udv.crm4.dynamics.com
"AADSTS500011: The resource principal named https://msys-udv.crm4.dynamics.com/.default was not found in the tenant named L\u00E6geforeningen. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You might have sent your authentication request to the wrong tenant. Trace ID: 0c597523-7623-4b36-a662-79c9d6454400 Correlation ID: 509b56b9-2a65-4cb6-a521-63805e718e89 Timestamp: 2024-10-17 07:12:42Z","errorCode":"invalid_resource","innerException":null,"statusCode":400,"message":null,"correlationId":"7ef5be25-f25f-4145-8049-ac9e6d82a7b1"} Headers: Date: Thu, 17 Oct 2024 07:12:42 GMT Server: Kestrel Transfer-Encoding: chunked X-CORRELATION-ID: REDACTED Content-Type: application/json; charset=utf-8 See the troubleshooting guide for more information. https://aka.ms/azsdk/net/identity/manag ... oubleshoot
Однако этот код работает с управляемым удостоверением, назначаемым системой. Поэтому, когда вызывается DefaultAzureCredentials, он работает нормально, но я не могу заставить работать ManagedIdentityCredential.
Что-то, что мне может не хватать?
private static async Task TokenProviderFunction(string dataverseUrl, string? clientId, ILogger logger)
{
// Use TokenCredential type to handle both DefaultAzureCredential and ManagedIdentityCredential
TokenCredential credential;
if (string.IsNullOrWhiteSpace(clientId))
{
logger.LogInformation("Using System-Assigned Managed Identity (DefaultAzureCredential).");
credential = new DefaultAzureCredential(); // Use System-Assigned Managed Identity
}
else
{
logger.LogInformation($"Using User-Assigned Managed Identity with Client ID: {clientId}");
credential = new ManagedIdentityCredential(clientId); // Use specific User-Assigned Managed Identity
}
var coreUrl = dataverseUrl;
var scopeString = $"{coreUrl}/.default";
var tokenRequestContext = new TokenRequestContext(new[] { scopeString });
try
{
logger.LogInformation("Requesting access token...");
var accessToken = await credential.GetTokenAsync(tokenRequestContext, CancellationToken.None);
logger.LogInformation("Access token successfully retrieved.");
return accessToken;
}
catch (Exception ex)
{
logger.LogError($"Failed to retrieve access token: {ex.Message}");
throw;
}
}
Подробнее здесь: https://stackoverflow.com/questions/790 ... ng-to-data