Follow React example fails with 401 from POST to /oauth/token
See original GitHub issueDescription
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 workingdomain
andclientId
- 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
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
- React Router Dom
Issue Analytics
- State:
- Created 3 years ago
- Comments:24 (11 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.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.