Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
0b38d95
Update documentation reference urls
abn Nov 16, 2017
24b7048
[KEYCLOAK-5928] - Update Node.js engine for keycloak-nodejs-connect
Nov 28, 2017
b3e925c
3.4.1-cr.1
keycloak-bot Nov 30, 2017
702976a
3.4.1
keycloak-bot Dec 8, 2017
68dfa11
[KEYCLOAK-5823] Access token is not getting renewed automatically in …
foo4u Dec 6, 2017
29d7f0b
3.4.2
keycloak-bot Dec 21, 2017
354b60f
KEYCLOAK-6121 Add package-lock.json
stianst Jan 3, 2018
11c2561
3.4.3
keycloak-bot Jan 4, 2018
cbab185
KEYCLOAK-5823 Fix mixed client service calls
foo4u Jan 2, 2018
4b3b6b1
KEYCLOAK-6161: Git ignores some specs causing semistandard to ignore …
foo4u Jan 9, 2018
01cf8a6
[KEYCLOAK-6171] Node.js adapter doesn't remove "session_state" from U…
Jan 30, 2018
f8ea017
Revert "[KEYCLOAK-6171] Node.js adapter doesn't remove "session_state…
Feb 1, 2018
3eb99ae
Fix for [KEYCLOAK-6171] Node.js adapter doesn't remove "session_state…
Feb 1, 2018
28e2968
KEYCLOAK-6464 Stabilize logout in tests
vmuzikar Feb 8, 2018
fe34e77
[KEYCLOAK-6093] grant_type refresh_token throws 'invalid_client_crede…
nsriram Dec 28, 2017
a159bed
4.0.0-beta.1
keycloak-bot Mar 22, 2018
10b19cc
KEYCLOAK-6909 / KEYCLOAK-6986 Upstream product build stuff
ASzc Mar 29, 2018
fda5b92
KEYCLOAK-7193 Correct base path in product build pom (#122)
ASzc Apr 20, 2018
dfe8590
Bump version to 4.0.0.Beta3 (#125)
stianst May 2, 2018
e327f96
KEYCLOAK-7343 Correct the paths defined for PME's jsonUpdate
ASzc May 14, 2018
b5224f1
Bump version to 4.0.0.Final
stianst May 24, 2018
76d9676
Node.js 4 reached it's EOL and we no longer should support it
Jun 4, 2018
a6c8617
Dependency Updates
Jun 4, 2018
a4d6083
Display promise error massage
onigra Feb 24, 2018
753dd2b
Update to 4.1.0.Final
stianst Jun 14, 2018
6eb72df
Fix incomplet token validation
sberthier Jun 7, 2018
6c118c4
Pass `next` to `accessDenied` method to allow error handling
lennym May 14, 2018
6286cf0
Fix cookie-store
piec Apr 24, 2020
a3f9e5d
Improve error handling
ashevel-smartling Aug 13, 2021
1cbf091
Merge branch '3.4.x-Smartling' into master1
ashevel-smartling Aug 13, 2021
154565e
Fix logging
ashevel-smartling Aug 16, 2021
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
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ sudo: required
dist: trusty
language: node_js
node_js:
- "4"
- "6"
- "7"
- "8"
Expand Down
7 changes: 2 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ Discussions can be done via:

Documentation:

[Web site docs](http://keycloak.jboss.org/docs) - User Guide, Admin REST API and Javadocs

[Git books](https://www.gitbook.com/@keycloak) - Authorization Services, Server Administration Guide, Server Developer Guide,
Server Installation and Configuration Guide, Securing Applications and Services Guide, Getting Started Guide

[Web site docs](http://www.keycloak.org/documentation.html) - Authorization Services, Server Administration Guide, Server Developer Guide,
Server Installation and Configuration Guide, Securing Applications and Services Guide, Getting Started Guide, Admin REST API and Javadocs

## Code contributions

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ authentication, including authenticating against various social networks
and OAuth providers (G+, Facebook, etc).

This module makes it simple to implement a Node.js Connect-friendly
application that uses Keycloak for its authentication and authorization needs. For usage instructions, please read the [documentation](https://keycloak.gitbooks.io/documentation/content/securing_apps/topics/oidc/nodejs-adapter.html).
application that uses Keycloak for its authentication and authorization needs. For usage instructions, please read the [documentation](http://www.keycloak.org/docs/latest/securing_apps/index.html#_nodejs_adapter).

Reporting security vulnerabilities
----------------------------------
Expand Down
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,9 @@ Keycloak.prototype.getGrant = function (request, response) {
self.storeGrant(grant, request, response);
return grant;
})
.catch(() => { return Promise.reject(); });
.catch((e) => {
return Promise.reject(new Error('Could not store grant code error. ' + e));
});
}

return Promise.reject();
Expand Down
23 changes: 13 additions & 10 deletions middleware/auth-utils/grant-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ GrantManager.prototype.ensureFreshness = function ensureFreshness (grant, callba

const params = {
grant_type: 'refresh_token',
refresh_token: grant.refresh_token.token
refresh_token: grant.refresh_token.token,
client_id: this.clientId
};
const handler = refreshHandler(this, grant);
const options = postOptions(this);
Expand Down Expand Up @@ -205,7 +206,7 @@ GrantManager.prototype.userInfo = function userInfo (token, callback) {
const promise = new Promise((resolve, reject) => {
const req = getProtocol(options).request(options, (response) => {
if (response.statusCode < 200 || response.statusCode >= 300) {
return reject('Error fetching account');
return reject(new Error('Error fetching account'));
}
let json = '';
response.on('data', (d) => (json += d.toString()));
Expand Down Expand Up @@ -282,10 +283,10 @@ GrantManager.prototype.createGrant = function createGrant (rawData) {
*/
GrantManager.prototype.validateGrant = function validateGrant (grant) {
var self = this;
const validateGrantToken = (grant, tokenName) => {
const validateGrantToken = (grant, tokenName, expectedType) => {
return new Promise((resolve, reject) => {
// check the access token
this.validateToken(grant[tokenName]).then(token => {
this.validateToken(grant[tokenName], expectedType).then(token => {
grant[tokenName] = token;
resolve();
}).catch((err) => {
Expand All @@ -295,13 +296,13 @@ GrantManager.prototype.validateGrant = function validateGrant (grant) {
};
return new Promise((resolve, reject) => {
var promises = [];
promises.push(validateGrantToken(grant, 'access_token'));
promises.push(validateGrantToken(grant, 'access_token', 'Bearer'));
if (!self.bearerOnly) {
if (grant.refresh_token) {
promises.push(validateGrantToken(grant, 'refresh_token'));
promises.push(validateGrantToken(grant, 'refresh_token', 'Refresh'));
}
if (grant.id_token) {
promises.push(validateGrantToken(grant, 'id_token'));
promises.push(validateGrantToken(grant, 'id_token', 'ID'));
}
}
Promise.all(promises).then(() => {
Expand All @@ -328,14 +329,16 @@ GrantManager.prototype.validateGrant = function validateGrant (grant) {
*
* @return {Promise} That resolve a token
*/
GrantManager.prototype.validateToken = function validateToken (token) {
GrantManager.prototype.validateToken = function validateToken (token, expectedType) {
return new Promise((resolve, reject) => {
if (!token) {
reject(new Error('invalid token (missing)'));
} else if (token.isExpired()) {
reject(new Error('invalid token (expired)'));
} else if (!token.signed) {
reject(new Error('invalid token (not signed)'));
} else if (token.content.typ !== expectedType) {
reject(new Error('invalid token (wrong type)'));
} else if (token.content.iat < this.notBefore) {
reject(new Error('invalid token (future dated)'));
} else if (token.content.iss !== this.realmUrl) {
Expand Down Expand Up @@ -363,8 +366,8 @@ GrantManager.prototype.validateToken = function validateToken (token) {
} else {
resolve(token);
}
}, () => {
reject(new Error('failed to load public key to verify token'));
}).catch((err) => {
reject(new Error('failed to load public key to verify token. Reason: ' + err.message));
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion middleware/auth-utils/rotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Rotation.prototype.retrieveJWKs = function retrieveJWKs (callback) {
const promise = new Promise((resolve, reject) => {
const req = getProtocol(options).request(options, (response) => {
if (response.statusCode < 200 || response.statusCode >= 300) {
return reject('Error fetching JWK Keys');
return reject(new Error('Error fetching JWK Keys'));
}
let json = '';
response.on('data', (d) => (json += d.toString()));
Expand Down
1 change: 1 addition & 0 deletions middleware/auth-utils/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function Token (token, clientId) {
this.signature = new Buffer(parts[2], 'base64');
this.signed = parts[0] + '.' + parts[1];
} catch (err) {
console.error('Failed to parse JWT token', err);
this.content = {
exp: 0
};
Expand Down
8 changes: 7 additions & 1 deletion middleware/grant-attacher.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ module.exports = function (keycloak) {
.then(grant => {
request.kauth.grant = grant;
})
.then(next).catch(() => next());
.then(next).catch(err => {
// err can be undefined
if (err) {
console.error('Failed to get grant', err);
}
next();
});
};
};
5 changes: 3 additions & 2 deletions middleware/post-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module.exports = function (keycloak) {
delete urlParts.query.code;
delete urlParts.query.auth_callback;
delete urlParts.query.state;
delete urlParts.query.session_state;

let cleanUrl = URL.format(urlParts);

Expand All @@ -48,8 +49,8 @@ module.exports = function (keycloak) {
}
response.redirect(cleanUrl);
}).catch((err) => {
keycloak.accessDenied(request, response);
console.error('Could not obtain grant code: ' + err);
keycloak.accessDenied(request, response, next);
console.error('Could not obtain grant code', err);
});
};
};
Loading