我正在尝试使用v2.0终结点(Microsoft App注册门户)通过Microsoft Graph访问SharePoint,但无法进行身份验证。
我正在使用以下代码。
var cca = new ConfidentialClientApplication(client_id, "https://login.microsoftonline.com/testtest.onmicrosoft.com/v2.0/", "http://localhost:61716/", new ClientCredential(password), null, null);
AuthenticationResult authResult = cca.AcquireTokenForClientAsync(new string[] { "https://graph.microsoft.com/.default" }).GetAwaiter().GetResult();
var graph = new GraphServiceClient(new DelegateAuthenticationProvider((message) =>
{
message.Headers.Authorization = new AuthenticationHeaderValue("bearer", authResult.AccessToken);
return Task.FromResult(0);
}));
我当前收到错误消息:“消息:令牌中必须包含scp或角色声明”。
如何向应用程序注册门户添加适当的权限,以及如何应用它们/从C#应用程序访问SharePoint。
编辑:我想澄清一下,我不想使用Azure AD,我想使用Microsoft App Registration Portal。
答案 0 :(得分:0)
需要在您的应用项目中添加权限。
Sites.Read.All, Sites.ReadWrite.All
如果您使用aspnet MVC,只需在Web配置(get started)中将 GraphScopes 修改为。
如果您使用NetCore,请从Github sample开始。然后在应用程序设置中修改 GraphScopes
如果您使用Angular,请从here开始,根据需要选择基于SDK或基于Rest。然后在config.js中设置 GraphScopes