-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
Category
- Bug
Describe the bug
My client has a provider-hosted app that has been in use for more than a year. The SharePoint add-in is deployed to the tenant App Catalog in SharePoint Online and the app is an ASP.NET web site deployed to Azure App Service. For the last several days the app has been receiving 401 errors when requesting app-only tokens.
Steps to reproduce
When the app is launched it fails when requesting the app-only token. The error status code is 401 and the error message is Token request failed. The remote server returned an error: (401) Unauthorized.
Full error call stack:
Microsoft.IdentityModel.SecurityTokenService.RequestFailedException: at Microsoft.IdentityModel.S2S.Protocols.OAuth2.OAuth2S2SClient.Issue (Microsoft.IdentityModel.Extensions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=69c3241e6f0468ca) at <ProductName>AppWeb.TokenHelper.GetAppOnlyAccessToken (<ProductName>AppWeb, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) at <ProductName>AppWeb.DAL.<ProductName>UnitOfWork..ctor (<ProductName>AppWeb, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) at <ProductName>AppWeb.SharePointContextFilterAttribute.SetControllerVars (<ProductName>AppWeb, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) at <ProductName>AppWeb.SharePointContextFilterAttribute.OnActionExecuting (<ProductName>AppWeb, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) at System.Web.Mvc.Async.AsyncControllerActionInvoker+AsyncInvocationWithFilters.InvokeActionMethodFilterAsynchronouslyRecursive (System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35) at System.Web.Mvc.Async.AsyncControllerActionInvoker+AsyncInvocationWithFilters.InvokeActionMethodFilterAsynchronouslyRecursive (System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35) at System.Web.Mvc.Async.AsyncControllerActionInvoker+<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__31 (System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35) at System.Web.Mvc.Async.AsyncResultWrapper+WrappedAsyncResult1.CallBeginDelegate (System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
at System.Web.Mvc.Async.AsyncResultWrapper+WrappedAsyncResultBase1.Begin (System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35) at System.Web.Mvc.Async.AsyncControllerActionInvoker.BeginInvokeActionMethodWithFilters (System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35) at System.Web.Mvc.Async.AsyncControllerActionInvoker+<>c__DisplayClass21.<BeginInvokeAction>b__19 (System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35) Inner exception System.Net.WebException handled at Microsoft.IdentityModel.S2S.Protocols.OAuth2.OAuth2S2SClient.Issue: at System.Net.HttpWebRequest.GetResponse (System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089) at Microsoft.IdentityModel.S2S.Protocols.OAuth2.OAuth2WebRequest.GetResponse (Microsoft.IdentityModel.Extensions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=69c3241e6f0468ca) at Microsoft.IdentityModel.S2S.Protocols.OAuth2.OAuth2S2SClient.Issue (Microsoft.IdentityModel.Extensions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=69c3241e6f0468ca)
Expected behavior
The request for the app-only token returns a 200 status code and includes the token.
Environment details (development & target environment)
- Add-in Environment: SharePoint Online
- App Environment: Azure App Service
- App Framework: .NET Framework v4.5
- Browser(s): Chrome v89
Additional context
I have confirmed the following.
- The Client ID and Client Secret are correctly configured in the app settings.
- DisableCustomAppAuthentication is set to false in the tenant settings.
- I can successfully get an app-only token by making a request in Fiddler
- In a .NET application that uses the PnP Sites Core library, I can successfully authenticate with SharePoint using the Client ID and Client Secret and get data from SharePoint.




