c# - AADSTS70011:为输入参数“范围”提供的值无效
问题描述
所以我有一个场景,其中应用程序应该在某些条件下将用户添加到组中。此外,当应用程序开始运行时,不应要求用户登录他们的 microsoft id/pwd。
因此,我访问了使用 Graph Service Client 对象创建的令牌,如下所示:
GraphServiceClient graphClient = new GraphServiceClient(
"https://graph.microsoft.com/v1.0",
new DelegateAuthenticationProvider(
async (requestMessage) =>
{
string clientId = "My APP ID";
string authorityFormat = "https://login.microsoftonline.com/{0}/v2.0";
string tenantId = "tenant GUID";
string[] _scopes = new string[] {
"https://graph.microsoft.com/User.ReadBasic.All"
};
// Custom Redirect URI asigned in the Application Registration
// Portal in the native Application Platform
string redirectUri = "https://localhost:4803/";
string clientSecret = "App Secret";
ConfidentialClientApplication daemonClient = new ConfidentialClientApplication(
clientId,
String.Format(authorityFormat, tenantId),
redirectUri,
new ClientCredential(clientSecret),
null, new TokenCache()
);
AuthenticationResult authResult = await daemonClient.AcquireTokenForClientAsync(_scopes);
string token = authResult.AccessToken;
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", token);
}
)
);
所以我尝试执行
var user = await graphClient.Me.Request().GetAsync();
我收到此错误:
AADSTS70011:为输入参数“范围”提供的值无效。范围 user.read 无效。
我也尝试使用 just User.ReadBasic
as 范围,但得到相同的错误。
我在这里做错了什么?
解决方案
您在此处使用客户端凭据流,这意味着您不能动态请求范围。您必须在 apps.dev.microsoft.com 中为您的应用注册配置所需的权限范围,然后将代码中的范围值设置为https://graph.microsoft.com/.default
.
有关更多详细信息,请参阅https://developer.microsoft.com/en-us/graph/docs/concepts/auth_v2_service。
推荐阅读
- sql - 如何在 SQLite 中替换查询的部分字段
- java - 在 Camunda 中禁用运行时数据库
- java - mapbox android添加航点
- flutter - 任何人都可以向我解释这段代码吗?
- spring-boot - 无法在 Grails 3 中获取 API 请求/响应负载日志记录
- sql - 将日期范围拆分为月份(使用 CTE)
- sql - SQL拆分字符串并结合第一次和第二次出现
- continuous-integration - TeamCity:在自定义构建中使用配置参数
- c# - INotifyDataErrorInfo(有时)不起作用
- python - 下面如何计算 dy(Tensorflow 中的上游梯度)?