question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Follow React example fails with 401 from POST to /oauth/token

See original GitHub issue

Description

Following the example for integrating this library into a new React app, using an existing client ID and domain which work with an older implementation of Auth0, result in a 401 Unauthorized response from /oauth/token.

Reproduction

Follow steps in the docs: https://auth0.com/docs/quickstart/spa/react

  • $ npx create-react-app my-app
  • $ cd my-app
  • $ npm install react-router-dom @auth0/auth0-spa-js
  • Create src/utils/history.js with provided content
  • Create src/react-auth0-spa.js with provided content
  • Create src/components/NavBar.js with provided content
  • Update src/index.js with provided content
  • Create auth_config.json with my working domain and clientId
  • Update src/App.js with provided content
  • Read “At this point, you should be able to go through the complete authentication flow: logging in and logging out.”
  • On attempting, get 401 Unauthorized error thrown

auth0-login

Checking the Network tab of the dev tools, a POST to https://<mydomain>/oauth/token faled with a 401. It had a payload including client_id, code, code_verifier, grant_type, and redirect_uri (which is on the allowed list).

Environment

  • Version of this library used: 1.8.2
  • Version of the platform or framework used, if applicable: React 16.13.1
  • Other relevant versions (language, server software, OS, browser): Chrome
  • Other modules/plugins/libraries that might be involved:
    • React Router Dom 5.2.0
    • React Scripts 3.4.1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:24 (11 by maintainers)

github_iconTop GitHub Comments

5reactions
cbrwizardcommented, Jul 28, 2020

I just had the same issue. I followed official React tutorial, but /oauth/token was returning 401 and the logs were not helpful at all. My solution was to go to Auth0 settings -> Applications -> Application Properties, change Application Type from Single Page Application to Regular Web Application, then switch Token Endpoint Authentication Method from POST to None, then switch Application Type back to Single Page Application. I’d say this is a dev UX bug at least.

3reactions
stevehobbsdevcommented, Jun 5, 2020

Can you confirm that your dashboard is configured like so? Your Auth0 client “Application Type” settings should be set to “Single Page Application” when using this SDK. In this configuration, you should be unable to configure the Token Endpoint Authentication Method setting.

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

401/Unauthorized when obtaining token in Authorization ...
Token Endpoint Authentication Method: field is inactive (greyed out) and set to “Post”; Advanced Setting->Grant Types: The following are checked ...
Read more >
Auth0 returns a 401 on token request. Auth0 logs show login ...
Looking at the log I get the following under the heading of a Failed Exchange . { "date": "2020-10-14T09:14:07.304Z", "type": ...
Read more >
'401 Unauthorized HTTP' for REST API token that expires in ...
Error : '401 Unauthorized HTTP' for REST API token that expires in less than 60 minutes.
Read more >
Best Practices | FedEx Developer Portal
It is recommended to cache the access token until the HTTP error code 401 is observed. Regenerate the OAuth token at that time....
Read more >
Authorization Code Flow (3-legged OAuth) - LinkedIn
Visit the LinkedIn Developer Portal Token Generator or follow the steps ... should return a 401 Unauthorized error code in response.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found