【发布时间】:2020-12-26 12:28:06
【问题描述】:
范围值 =“https://graph.microsoft.com/.default”或“https://graph.microsoft.com/beta”
在 asp.net c# 中给出以下错误。
MsalServiceException:AADSTS500011:资源主体名为 在名为的租户中找不到https://graph.microsoft.com/v1.0 'xxxxxxxx'。如果尚未安装应用程序,可能会发生这种情况 由租户的管理员或由租户的任何用户同意 租户。您可能将身份验证请求发送到了错误的位置 租户。
代码:
string clientId = AppClientID;
string clientSecret = Secret;
string redirectUri =`enter code here` System.Configuration.ConfigurationManager.AppSettings["redirectUri"];
string authority = "https://login.microsoftonline.com/" + tenantID;
string[] scopes = new string[] { "https://graph.microsoft.com/.default" };
//string[] scopes = new string[] { "https://graph.microsoft.com/beta/.default" };
IConfidentialClientApplication app = ConfidentialClientApplicationBuilder
.Create(clientId)
.WithRedirectUri(redirectUri)
.WithClientSecret(clientSecret)
.WithAuthority(authority)
.Build();
AuthorizationCodeProvider auth = new AuthorizationCodeProvider(app, scopes);
GraphServiceClient graphServiceClient = new GraphServiceClient(new DelegateAuthenticationProvider(async (requestMessage) =>
{
var authResult = app.AcquireTokenForClient(scopes).WithAuthority(authority, true).ExecuteAsync().Result.AccessToken.ToString();
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", authResult);
}));
var onlineMeeting = new OnlineMeeting
{
StartDateTime = DateTimeOffset.Parse("2021-07-12T21:30:34.2444915+00:00"),
EndDateTime = DateTimeOffset.Parse("2021-07-12T22:00:34.2464912+00:00"),
Subject = "My First MS Teams Meeting"
};
await graphServiceClient.Me.OnlineMeetings.Request().AddAsync(onlineMeeting);
【问题讨论】:
-
请将
scope改为:https://graph.microsoft.com/.default -
使用范围 = graph.microsoft.com/.default .posted code in question.plz check.
-
仍然出现同样的错误?我没有看到
https://graph.microsoft.com/v1.0放在您的代码中的任何位置。 -
我是新来的,所以谢谢格式化@Allen。当我尝试'graph.microsoft.com/v1.0'时,我得到的参数'范围'无效。范围graph.microsoft.com/v1.0 无效。
-
不要使用
https://graph.microsoft.com/v1.0或https://graph.microsoft.com/v1.0/.default。正如卡尔建议的那样,使用https://graph.microsoft.com/.default。如果您将范围设置为https://graph.microsoft.com/.default,我认为您在此处发布的错误不会发生。
标签: c# asp.net azure-active-directory microsoft-graph-api