【发布时间】:2021-10-14 23:44:49
【问题描述】:
我正在尝试使用 Postman 进行身份验证以获取 Azure AD 不记名令牌,然后将令牌发送到我的本地 WebApi .net Core 服务器,该服务器应该验证令牌并向 Graph API 发送请求。但在过去的几个小时里,我被这个错误困住了。
Microsoft.Identity.Client.MsalUiRequiredException:AADSTS65001: 用户或管理员未同意使用带有 ID 的应用程序 'b6590b93-aeba-45e1-b337-f52695e3647e' 命名 'RegistryCrawlePublicWebApi'。发送交互式授权 请求此用户和资源。
Azure 门户 API 权限:
namespace WebApiUsingGraphApi.Controllers
{
[Authorize]
[ApiController]
[Route("[controller]")]
public class GraphCallsController : ControllerBase
{
private readonly GraphApiClientDirect _graphApiClientDirect;
public GraphCallsController(GraphApiClientDirect graphApiClientDirect)
{
_graphApiClientDirect = graphApiClientDirect;
}
[HttpGet]
public async Task<string> Get()
{
var user = await _graphApiClientDirect.GetGraphApiUser()
.ConfigureAwait(false);
// var photo = await _graphApiClientDirect.GetGraphApiProfilePhoto();
// var file = await _graphApiClientDirect.GetSharepointFile();
return user.DisplayName;
}
}
}
Startup.cs
services.AddMicrosoftIdentityWebApiAuthentication(Configuration)
.EnableTokenAcquisitionToCallDownstreamApi()
.AddInMemoryTokenCaches();
【问题讨论】:
标签: c# azure asp.net-core