I need some help, I couldn’t find a similar issue on SO or Auth0 community. I’m using the https
module to connect to an Auth0 endpoint from localhost
. It’s unlikely that the endpoint doesn’t exist but I’m getting a 404 response. I’ve checked my Auth0 config as well and seems fine.
Below are the request options I’ve tried (option 1 is an example from Auth0), the server/request code, and the response to each set of options. Could this be an issue with the certificates I’m using? I installed root CAs and used along with a self-signed certificate, but that wouldn’t result in a 404.
Server:
const https = require('https');
const fs = require('fs');
const path = require('path');
const express = require('express');
const rootCA = require('ssl-root-cas/latest').create().addFile(__dirname+'/cert/CA.pem');
const port = process.env.PORT || 443;
const app = express();
const httpsOptions = {
key: fs.readFileSync(path.join(__dirname, './cert/localhost.key')),
cert: fs.readFileSync(path.join(__dirname, './cert/localhost.crt'))
};
https.globalAgent.options.ca = rootCA;
app.use(require('cookie-parser')(process.env.COOKIE_SECRET));
app.use(express.json());
app.use('/auth', require('./Auth'));
const server = https.createServer(httpsOptions, app).listen(port, () => { console.log(`server running on port ${port}`); });
https.request options I’ve tried:
// Option #1
var options = {
method: 'POST',
url: 'https://mytenant.us.auth0.com/oauth/token',
headers: { 'content-type': 'application/json' },
body: '{"client_id":"myclientid","client_secret":"myclientsecret","audience":"https://localhost:443/user/search","grant_type":"client_credentials"}'
};
// Option #2
var options = {
method: 'POST',
host: 'mytenant.us.auth0.com',
port: 443,
url: 'https://mytenant.us.auth0.com/oauth/token',
headers: { 'content-type': 'application/json' },
body: '{"client_id":"myclientid","client_secret":"myclientsecret","audience":"https://localhost:443/user/search","grant_type":"client_credentials"}'
};
Auth module mounted on Express app:
const express = require('express');
const router = express.Router();
const https = require('https');
router.post('/token', (req, res) => {
var options = {
// see above
},
r = https.request(options, (response) => {
console.log('statusCode:', response.statusCode);
console.log('headers:', response.headers);
response.on('data', (d) => {
console.log(d.toString());
});
});
r.on('error', (e) => {
console.error(e);
});
r.end();
});
module.exports = router;
Response to https.request Option #1:
statusCode: 404
headers: {
'x-powered-by': 'Express',
'x-ratelimit-limit': '100',
'x-ratelimit-remaining': '99',
date: 'Wed, 23 Sep 2020 12:31:14 GMT',
'x-ratelimit-reset': '1600865142',
'content-security-policy': "default-src 'none'",
'x-content-type-options': 'nosniff',
'content-type': 'text/html; charset=utf-8',
'content-length': '140',
connection: 'close'
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot POST /</pre>
</body>
</html>
Response to https.request Option #2:
statusCode: 404
headers: {
date: 'Wed, 23 Sep 2020 16:28:37 GMT',
'content-type': 'text/plain; charset=utf-8',
'content-length': '10',
connection: 'close',
server: 'nginx',
'ot-tracer-spanid': '08d8bd90433cda10',
'ot-tracer-traceid': '07cd8fe13ee97d50',
'ot-tracer-sampled': 'true',
'ot-baggage-auth0-request-id': 'a6e2793b76752b11b4cad24a',
'x-auth0-requestid': 'd724a321a207298ad58b',
'set-cookie': [
'did=s%3Av0%3Ad50c1f60-fdb9-11ea-a311-2b10561c1c2c.LAjk%2BY%2BXs2rIpTslhu5IzLiIlWSp6fNdZDtfbLRmJNY; Max-Age=31557600; Path=/; Expires=Thu, 23 Sep 2021 22:28:37 GMT; HttpOnly; Secure; SameSite=None',
'did_compat=s%3Av0%3Ad50c1f60-fdb9-11ea-a311-2b10561c1c2c.LAjk%2BY%2BXs2rIpTslhu5IzLiIlWSp6fNdZDtfbLRmJNY; Max-Age=31557600; Path=/; Expires=Thu, 23 Sep 2021 22:28:37 GMT; HttpOnly; Secure'
],
'x-auth0-not-found': '1',
etag: 'W/"a-8RJARPvfYzJdDi+ZdXbdTOYnAfo"',
'cache-control': 'private, no-store, no-cache, must-revalidate, post-check=0, pre-check=0, no-transform',
'strict-transport-security': 'max-age=31536000'
}
Not found.