Why am I getting 'UnauthorizedError: No authorization token was found" when matching example?

I have the following basically matching the example…

var express = require('express');
var app = express();
var jwt = require('express-jwt');
var jwks = require('jwks-rsa');

var port = process.env.PORT || 8080;

const checkJwt = jwt({
    secret: jwks.expressJwtSecret({
        cache: true,
        rateLimit: true,
        jwksRequestsPerMinute: 5,
        jwksUri: `https://.../.well-known/jwks.json`
    }),
    audience: 'https://...',
    issuer: [`https://.../`],
    algorithms: ['RS256']
}).unless({path: ['/']});
app.use(checkJwt)
app.get('/', function (req, res) {
    res.send('Clear');
});
app.get('/authorized', function (req, res) {
    res.send('Secured Resource');
});

app.listen(port);

But when I try going to http://localhost:8080/authorized I get…

UnauthorizedError: No authorization token was found
    at middleware (/Users/.../Code/tmp/auth0/node_modules/express-jwt/lib/index.js:79:21)
    at /Users/.../Code/tmp/auth0/node_modules/express-unless/index.js:47:5
    at Layer.handle [as handle_request] (/Users/.../Code/tmp/auth0/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/Users/.../Code/tmp/auth0/node_modules/express/lib/router/index.js:317:13)
    at /Users/.../Code/tmp/auth0/node_modules/express/lib/router/index.js:284:7

What am I missing?

So I get the problem is there is no token in the authorization header now. The real question is how do I add it? I see the token is in the cookies from openId connect but when I try to grab it on the server side like…

audience: 'https://...',
issuer: [`https://...`],
algorithms: ['RS256'],
getToken: (req)=>{
    console.log(`trying to get token ${JSON.stringify(req.cookies["token"])}`)
    return req.cookies["token"];
}

I get

trying to get token undefined

1 Like