Код: Выделить всё
using Azure.Identity;
using System;
using System.Threading.Tasks;
public class GraphApiService
{
private readonly GraphServiceClient _graphServiceClient;
public GraphApiService(string tenantId, string clientId, string clientSecret)
{
var credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
_graphServiceClient = new GraphServiceClient(credential, new[] { "https://graph.microsoft.com/.default" });
}
public async Task UserExists(string userId)
{
try
{
var user = await _graphServiceClient.Users[userId].Request().GetAsync();
return true;
}
catch (ServiceException ex)
{
Console.WriteLine($"Error getting user: {ex.Message}");
return false;
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/788 ... -an-except