06-25-2019 02:10 AM
06-25-2019 02:10 AM
When building a ClientContext based on an App ID and ClientSecret, you get an access denied while trying to access a SharePoint site. I have tried setting several API permissions, separately for SharePoint or Microsoft Graph, but the behavior stays the same.
var authManager = new AuthenticationManager();
using (var clientContext = authManager.GetAppOnlyAuthenticatedContext(siteUrl, _sharePointSettings.AppId, _sharePointSettings.AppSecret))
07-10-2019 06:55 AM
@Mathieu Marchant Did you use this method to create the app id and secret - https://docs.microsoft.com/en-us/sharepoint/dev/solution-guidance/security-apponly-azureacs
If so what's the XML you used for the permissions?
07-10-2019 07:12 AM
@Toby Statham I used the Azure Portal to register a new App under "Azure Active Directory" and from there I generated a new secret. Additionally I also added SharePoint related "API permissions" from there.
However I still get an access denied. So what I need to do, is lookup the app with the appinv.aspx from within SharePoint and add additional permissions from there with the xml.
What I would expect, is that setting the API permissions from the Azure Portal would be enough, but that doesn't seem to be the case. Is suppose by using the AuthenticationManager, the credentials are built up in a different way?
07-10-2019 09:36 AMSolution
07-18-2019 07:47 PM
Please make sure you granted appropriate API permission to Azure AD app for SharePoint. You can do it by going to Azure AD and then 'App Registration' and then 'API Permissions'. Under Microsoft APIs, select SharePoint and then provide either delegated or application permission based on your requirement.
07-18-2019 08:06 PM
07-18-2019 10:22 PM
@Rahul Suryawanshi The original poster had already done that, but was still getting an error. The problem is because a certificate needs to be created if you're accessing the SharePoint API using an Azure App registration (as detailed in the links I've provided in my replies). If you're using the GetAppOnlyAuthenticatedContext method you need to get the client id and secret through the SharePoint App registration method in AppRegNew.aspx
07-18-2019 10:55 PM
@Toby Statham. Okay, Yeah, For the high trust, Sharepoint app requires certificate-based authentication. Thanks for pointing out to me.