express-jwt icon indicating copy to clipboard operation
express-jwt copied to clipboard

Getting a 401, even with valid token

Open Sashkan opened this issue 8 years ago • 3 comments

I'm trying to connect to the sample project API, from a react app. Code is pretty simple:

I got a valid idToken (Checked it in JWT.io debugger), using the RS256 algorithm

I got the exact project with valid credentials (Downloaded it so that the .env file is already set with my credentials.

My React app calls the exact same function as in the documentation, except I replaced 'YOUR ID TOKEN HERE' with the valid one, obviously:

var request = require("request");

var options = { method: 'GET',
  url: 'http://localhost:8000/path_to_your_api',
  headers: { authorization: 'Bearer ' + authResult.idToken } };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

Even with this simple configuration, I cannot get to access /api/private, it keeps raising a 401.

Did I miss something ? Is there anything else to configure beside what's specified in the documentation ?

Sashkan avatar Apr 03 '17 10:04 Sashkan

possible causes

Did you change your secret?

recover

remember to clearCookie after this happens.

https://github.com/kriasoft/react-starter-kit/pull/1242#issuecomment-297791353

Stupidism avatar Apr 27 '17 19:04 Stupidism

@auth0alec I think you should add some documentation for error-recover in https://github.com/auth0/express-jwt#error-handling part

Stupidism avatar Apr 27 '17 19:04 Stupidism

This may be relevant https://github.com/jfromaniello/express-unless/issues/6#issuecomment-646728011

molaeiali avatar Jun 19 '20 16:06 molaeiali