SharePoint Add-In - Failure to acquire App-Only token

Chris Clum 26 Reputation points
2021-05-19T15:18:44.393+00:00

I have a SharePoint Add-In application that has been running for fine for a while with on coding changes and yesterday an error suddenly started to happen when attempting to get an app-only token:

Exception: Token request failed.
Inner Exception: The remote server returned an error: (401) Unauthorized.

The client ID/secret doesn't expire until next year. The application is running on .Net 4.7.2 and should be using TLS 1.2.

What could be the problem?

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,600 questions
0 comments No comments
{count} votes

Accepted answer
  1. MichaelHan-MSFT 18,016 Reputation points
    2021-05-24T02:28:11.817+00:00

    @Chris Clum ,

    The same issue was discussed here: https://github.com/pnp/pnpframework/issues/336. Windows 2012 R2 and worked intermittently.

    Make sure the server supports one of supported cyphers:

    • TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
    • TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
    • TLS_DHE_RSA_WITH_AES_256_GCM_SHA38
    • TLS_DHE_RSA_WITH_AES_128_GCM_SHA256

    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. MichaelHan-MSFT 18,016 Reputation points
    2021-05-20T02:48:00.837+00:00

    Hi @Chris Clum ,

    This could be that the SharePoint app-only permissions is disabled for you tenant. You could check it with this command: get-spotenant | select DisableCustomAppAuthentication

    And you could run the below cmdlet to enable it: Set-SPOTenant -DisableCustomAppAuthentication $false


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. Leonardo da Silva Brito 1 Reputation point
    2022-09-23T20:25:31.913+00:00

    It is necessary to look at the exception message, because in my case I had a solution that had two projects and after installing the pnp framework the solution was with newtonsoft.json v12 and in the other project it was with newtonsoft.json v10, I discovered this by the message from exception - "Could not load file or assembly 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of the important dependencies. The assembly manifest definition does not match the reference to the assembly. ( Exception from HRESULT: 0x80131040)":"Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed", after discovering this I updated them both to have v12 and it worked.

    0 comments No comments