< /li>
Функция контроллера: < /p>
< /li>
< /ol>
< /p>
< /li>
< /ol>
[HttpGet]
public async Task Index()
{
try
{
var graphServiceClient = GetGraphServiceClient();
var entraIDUser = await graphServiceClient.Me.GetAsync();
return View();
}
catch (Exception ex)
{
_logger.LogError("An error occured when trying to return Index page: " + ex.Message);
return StatusCode(500, "An error occured when trying to return Index page");
}
}
< /code>
- GetGraphServiceClient функция, которая создает экземпляр GraphServiceClient:
{
var scopes = new[] { "User.Read" };
var tenantId = _configuration.GetValue("AzureAd:TenantId");
var clientId = _configuration.GetValue("AzureAd:ClientId");
var options = new DeviceCodeCredentialOptions
{
AuthorityHost = AzureAuthorityHosts.AzurePublicCloud,
ClientId = clientId,
TenantId = tenantId,
DeviceCodeCallback = (code, cancellation) =>
{
Console.WriteLine(code.Message);
return Task.FromResult(0);
},
};
var deviceCodeCredential = new DeviceCodeCredential(options);
var graphClient = new GraphServiceClient(deviceCodeCredential, scopes);
return graphClient;
}
Подробнее здесь: https://stackoverflow.com/questions/787 ... et-core-mv