Azure App Service Can't Access SharePoint

Viewed 57

We have a simple Azure App Service app and part of that app accesses a SharePoint doc library to upload files. This has worked for years but recently stopped working. We generated a new clientid and secret thinking that was the problem - still no luck. We have been working with Microsoft for 3 weeks on the problem and they have been useless - they don't even know what a doc library is most the time and all they do is "take screenshots and will get back."

I can get a token and use it to pull resources in Postman just fine.

The following is the code in web.config:

 `<appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    <add key="ida:ClientId" value="spclientid" />
    <add key="ida:AADInstance" value="https://login.microsoftonline.com/" />
    <add key="ida:ClientSecret" value="spclientsecret" />
    <add key="ida:Domain" value="ourdomain.com" />
    <add key="ida:TenantId" value="tenantid" />
    <add key="ida:PostLogoutRedirectUri" 
value="https://login.microsoftonline.com/common/oauth2/v2.0/logoutsession/" />
</appSettings>`

Errors:

Error 1

Error 2

Error 3

At our rope's end with this one, any ideas?

Thanks in advance.

1 Answers

• You must use ‘AllowAppOnlyPolicy=true’ in your manifest file for the registered Azure AD sharepoint app to acquire token from the registered application in Azure AD on behalf of the service principal created through your ‘App Service’. Also, you can grant the required permissions for accessing the sharepoint online website through your ‘App service’ as shown below in the snapshot through the Azure AD app registration portal instead of the ‘App manifest’ file: -

Azure AD APIs

Azure AD API permission

Thus, when you are providing the correct permissions to the ‘Sharepoint’ portal through this ‘Service Principal’ in Azure AD for OAuth 2.0 as well as configuring the ‘Authentication’ token and protocols too correctly, the Azure App Service should be able to access the Sharepoint doc library to upload files.

• Finally, please once again check the correct value of the secret ID and its value that is being used to connect to the sharepoint website on behalf of the SP app in Azure AD. Also, do check the correct tenant ID, domain and AADInstance of the registered SP for your app service, the details of which you have mentioned in the ‘App settings.json’ file of the code.

For more details and clarification on this, kindly refer to the below links explaining the issues regarding the ‘Sharepoint’ token helper issues and CSOM platform issues regarding various browsers that are used to try to access the same: -

https://github.com/SharePoint/sp-dev-docs/issues/6955

https://docs.microsoft.com/en-us/sharepoint/dev/spfx/use-aadhttpclient

Related