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 = "[url]";
    string aadAppId = "[appid]";
    string clientSecret = "[redacted]";
    OfficeDevPnP.Core.AuthenticationManager authManager = new OfficeDevPnP.Core.AuthenticationManager();
    ClientContext context = authManager.GetAzureADNativeApplicationAuthenticatedContext(siteUrl, aadAppId, appurl, 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://domainname.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.

user1339913
  • 1,017
  • 3
  • 15
  • 36

1 Answers1

0

You example is attempting to retrieve a token as a native client application, which is an app that cannot keep a secret and cannot authenticate by itself. (That's why you'll notice you never use clientSecret.)

If you want to use OfficePnP, you can try one of the AuthenticationManager.GetAzureADAppOnlyAuthenticatedContext methods to authenticate in the app-only context. Note that they all require a certificate for authentication, rather than a secret.

Philippe Signoret
  • 13,299
  • 1
  • 40
  • 58
  • Thank you Philippe for the reply, but that would require me to install a certificate . Is there any way to achieve it without having to install a certificate. – user1339913 Dec 11 '18 at 20:26
  • Could you share some details on your use case where you can't use a certificate? – Philippe Signoret Dec 12 '18 at 00:07
  • Hi Philiippe, I can't install a certificate as I do not have rights and the admin did not want to install a certificate in Azure – user1339913 Dec 16 '18 at 11:14