c# - 尝试获取 MS Graph API 的令牌时缺少用户的 ImmutableID(Windows 身份验证)
问题描述
我正在开发一个 API,它使用 Microsoft Graph 客户端 SDK 对 Sharepoint 站点进行多次调用。
为了对调用 API 的用户进行身份验证,我使用了 Integrated Windows Provider 方法,代码非常简单:
var clientApp = PublicClientApplicationBuilder
.Create(_apiSettings.Value.AzureClientId)
.WithTenantId(_apiSettings.Value.AzureTenantId)
.Build();
var token = clientApp.AcquireTokenByIntegratedWindowsAuth(new string[] { _apiSettings.Value.MicrosoftGraphApiScopeUrl })
.ExecuteAsync().Result;
在本地调用包含此代码的方法时,它可以完美运行。但是,当我将应用程序部署到我们的测试服务器时,并通过与本地用户相同的用户使用 NTLM 身份验证,我遇到了这个错误:
Microsoft.Identity.Client.MsalUiRequiredException:AADSTS90020:SAML 1.1 断言缺少用户的 ImmutableID。
在打印 HttpContext.User 的内容时,我看到同一个用户,连接到同一个组,同时用于“在线”和本地版本。
我已经尝试添加此标头,但它没有做任何事情:
var immId = new Dictionary<string, string>();
immId.Add("Prefer", "IdType=\"ImmutableId\"");
var token = clientApp.AcquireTokenByIntegratedWindowsAuth(new string[] { _apiSettings.Value.MicrosoftGraphApiScopeUrl })
.WithExtraHttpHeaders(immId)
.ExecuteAsync().Result;
我能做些什么 ?
谢谢!
解决方案
If your application don't have the admin to consent to the application.You will get the MsalUiRequiredException
.
Try with the adding the admin consent to application .
Or Try with adding tenant admin selected the Grant/revoke admin consent for {tenant domain} button on the API permissions tab of the registration for the application. For more information, see Add permissions to access your web API.
For more details refer this document
推荐阅读
- c - 从 STDIN 逐行读取并将其写入输出文件
- qt5 - 取消停靠后 QOpenGLWidget 上的文本消失
- javascript - 当我想调用函数时如何调用布尔 isTested
- azure-devops - 备份/恢复 AzureDevOps
- javascript - 声明这个函数的两种方式有什么区别?
- android - Andrpoid 混合模式无法按预期工作
- java - Spring事务配置减去Exception(`-Exception`)的含义
- python - 无法将 INSERT 查询中的 POINT 数据类型转换为 PostgreSQL。需要插入表格的经度、纬度
- php - 通过 function.php 的古腾堡核心/列属性
- r - 如果没有收到错误消息,我无法将我的情节编织成 PDF