Forum Discussion

akshays's avatar
2 years ago

Receiving a 401 Authorization Required error on POST call to get Access Token via OAuth 2

I am able to get the Authorization code in the browser following the first step of OAuth 2.0 grant flow: https://developer.khoros.com/khoroscommunitydevdocs/reference/request-auth-code-lithium-registration


But getting a 401 Error on the call to get Access Token

Here is the call I am making:

method: 'POST'
url: 'https://wxample.example.com/api/2.0/auth/accessToken'

headers:
{'client_id':<URL_DECODED_CLIENT_ID>','content-type': 'application/json'}

data:
{
client_id: '<URL_DECODED_CLIENT_ID>',
client_secret: '<URL_DECODED_CLIENT_SECRET>',
code: '<URL_DECODED_AUTHORIZATION_CODE>',
grant_type: 'authorization_code',
redirect_uri: '<REDIRECT_URI_IN_APP>'
}

Receiving:

401 Authorization Required

Relevant docs: https://developer.khoros.com/khoroscommunitydevdocs/reference/request-auth-token-oauth

Any help would be appreciated.


  • MattV's avatar
    MattV
    Khoros Staff

    The instance probably has BasicAuth enabled (we frequently call it HTACCESS). You will have to pass the BasicAuth header with the appropriate credentials.

    • akshays's avatar
      akshays
      Ace

      Hi MattV ,

      Thanks for the info. But, I believe the error could be on the API. I purposefully malformed the call ( client_id and code ) but received the same 401 error. This is sort of weird because the error I am receiving does not seem to be relevant with the actual issue. Any suggestions?

      Appreciate the help.