Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ Here is what an auth configuration file looks like:
"AUTH0_CLIENT_ID": "xlkihjaskjhaskjjh",
"AUTH0_CLIENT_SECRET": "sdlkjsdlkjsdlkjsdl/kjsd;lklksdjhlksjdh",
"AUTH0_ALGORITHM": "RS256",
"AUTH0_AUDIENCE": "YOURAUDIENCE",
"AUTH0_DOMAIN": "YOURDOMAIN.auth0.com",
"AUTH0_HOST": "https://YOURDOMAIN.auth0.com",
"AUTH0_LOGIN_URL": "https://YOURDOMAIN.auth0.com/login",
"AUTH0_LOGIN_URL": "https://YOURDOMAIN.auth0.com/authenticate",
"CALLBACK_PATH": "/logincb"
}
```
Expand All @@ -55,6 +56,7 @@ Here is a description of each field:
* `AUTH0_CLIENT_ID` - the client id of the Auth0 Applicaton you are using to protect your site. Get from your Auth0 dashboard
* `AUTH0_CLIENT_SECRET` - the client secret of the Auth0 Application.
* `AUTH0_CLIENT_ALGORITHM` - either `"RS256"` or `"HS256"` depending on how your Auth0 application is configured
* `AUTH0_AUDIENCE` - id of the api audience
* `AUTH0_DOMAIN` - your Auth0 domain, aka `your-auth0-tenant.auth0.com`
* `AUTH0_HOST` - the url to your auth0 tenant aka `https://your-auth0-tenant.auth0.com`
* `AUTH0_LOGIN_URL` - the url to your app's login page
Expand Down
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function validateToken(config, token) {
try {
const decoded = jsonwebtoken.verify(token, config.certificate, {
algorithms: [config.AUTH0_ALGORITHM],
audience: config.AUTH0_CLIENT_ID,
audience: config.AUTH0_AUDIENCE,
});

return true;
Expand Down Expand Up @@ -65,6 +65,7 @@ function loginCallback(config, request, callback) {
client_id: config.AUTH0_CLIENT_ID,
redirect_uri: `https://${headers.host[0].value}${config.CALLBACK_PATH}`,
client_secret: config.AUTH0_CLIENT_SECRET,
audience: config.AUTH0_AUDIENCE,
code: params.code,
grant_type: "authorization_code"
});
Expand All @@ -88,7 +89,7 @@ function loginCallback(config, request, callback) {
res.on('end', () => {
try {
const json = JSON.parse(body);
const token = json.id_token;
const token = json.access_token;

if (!token) {
return callback(null, respond(401, "Unauthorized", "Unauthorized", body));
Expand Down Expand Up @@ -129,7 +130,7 @@ function redirectIfNotAuthenticated(config, request, callback) {
const encodedRedirectUrl = encodeURIComponent(request.querystring ? `${request.uri}?${request.querystring}` : request.uri);
const callbackUrl = `https://${headers.host[0].value}${config.CALLBACK_PATH}?dest=${encodedRedirectUrl}`;
const encodedCallback = encodeURIComponent(callbackUrl);
const redirectUrl = `${config.AUTH0_LOGIN_URL}?client=${config.AUTH0_CLIENT_ID}&redirect_uri=${encodedCallback}`;
const redirectUrl = `${config.AUTH0_LOGIN_URL}?client_id=${config.AUTH0_CLIENT_ID}&redirect_uri=${encodedCallback}&audience=${config.AUTH0_AUDIENCE}&&response_type=code&state=${Date.now()}`;

callback(null, redirect(redirectUrl, [{name: "session-token", value: ""}]));

Expand Down