0

I am accessing SharePoint online list data using the following code but i get the following error.

The remote server returned an error: (403) Forbidden.

The web forms application is running in Azure and uses Azure authentication. I would like to use the same credentials for authentication

string siteUrl = "[siteurl]";
string aadAppId = "[appid]";
string clientSecret = "[clientsecret]";
OfficeDevPnP.Core.AuthenticationManager authManager = new OfficeDevPnP.Core.AuthenticationManager();
ClientContext context = authManager.GetAzureADNativeApplicationAuthenticatedContext(siteUrl, aadAppId, @"[redirecturl]", null, AzureEnvironment.Production);
    if (context != null)
        {
         Web web = context.Web;
         context.Load(web);
         context.ExecuteQuery();
        }

I do not want to access the SharePoint using the user credentials.

I have enabled AAD Azure authentication on the web app. The web app authenticates with Azure credentials.

On the CORS setting i have also set the Domain Url to "https://domain.sharepoint.com";

In the manage permissions section of AAD app I have given the app Permission to read and write sharepoint list and web data.

  • Don't know Azure too much, but this is what the Secure Store is for. See if you can set it up in your Azure farm. – lazoDev Dec 11 '18 at 20:54
  • Have you tried to use that AAD App to access SPO via Graph API successfully? Another way you can test is to get the token and see if you have permission you need. – Verona Chen Dec 13 '18 at 18:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.