0
votes

I am trying to access SharePoint through Microsoft Graph using the v2.0 endpoint (Microsoft App Registration Portal) but I am unable to authenticate.

I am using the following code.

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);
        }));

I am currently getting the error "Message: Either scp or roles claim need to be present in the token."

How do I add the appropriate permissions to the app registration portal and how do I apply them / access SharePoint from my C# application.

Edit: I would like to clarify that I do not want to use the Azure AD, I would like to use the Microsoft App Registration Portal.

1

1 Answers

0
votes

The permission need to add in your Application project.

Sites.Read.All, Sites.ReadWrite.All

If you use aspnet MVC, just modify the GraphScopes to in web config(get started).

If you use NetCore, just get started from the Github sample. Then modify the GraphScopes in appsettings

If you use Angular, just get started from here,choose SDK-based or Rest-based for your requirement. Then set the GraphScopes in config.js