【问题标题】:Azure AD - AADSTS65001: The user or administrator has not consented to use the application with IDAzure AD - AADSTS65001:用户或管理员未同意使用 ID 的应用程序
【发布时间】: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


【解决方案1】:

Microsoft.Identity.Client.MsalUiRequiredException: AADSTS65001

对于上述.net中的错误,基于MS DOC

首先征得用户同意。如果您没有使用 .NET Core(没有任何 Web UI),请致电(仅一次)AcquireTokeninteractive。如果您正在使用 .NET 核心或不想执行 AcquireTokenInteractive,用户可以导航到 URL 以表示同意:https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id={clientId}&amp;response_type=code&amp;scope=user.read。拨打AcquireTokenInteractive:app.AcquireTokenInteractive(scopes).WithAccount(account).WithClaims(ex.Claims).ExecuteAsync();

有关更多信息,请参阅此 SO THREAD:AADSTS65001: The user or administrator has not consented to use the application with ID '

【讨论】:

    猜你喜欢
    • 2020-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-06
    • 2021-05-24
    • 2022-01-15
    • 1970-01-01
    相关资源
    最近更新 更多