Skip to content

Commit

Permalink
Bump semistandard from 13.0.1 to 16.0.1 (#332)
Browse files Browse the repository at this point in the history
* Bump semistandard from 13.0.1 to 16.0.1

Bumps [semistandard](https://github.com/standard/semistandard) from 13.0.1 to 16.0.1.
- [Release notes](https://github.com/standard/semistandard/releases)
- [Changelog](https://github.com/standard/semistandard/blob/master/CHANGELOG.md)
- [Commits](https://github.com/standard/semistandard/commits/v16.0.1)

---
updated-dependencies:
- dependency-name: semistandard
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Jon Koops <jonkoops@gmail.com>
  • Loading branch information
dependabot[bot] and jonkoops authored Jan 21, 2022
1 parent ccb6c84 commit 45d15d6
Show file tree
Hide file tree
Showing 28 changed files with 1,922 additions and 2,474 deletions.
20 changes: 10 additions & 10 deletions example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
* the License.
*/

var Keycloak = require('keycloak-connect');
var hogan = require('hogan-express');
var express = require('express');
var session = require('express-session');
const Keycloak = require('keycloak-connect');
const hogan = require('hogan-express');
const express = require('express');
const session = require('express-session');

var app = express();
const app = express();

var server = app.listen(3000, function () {
var host = server.address().address;
var port = server.address().port;
const server = app.listen(3000, function () {
const host = server.address().address;
const port = server.address().port;
console.log('Example app listening at http://%s:%s', host, port);
});

Expand All @@ -41,7 +41,7 @@ app.get('/', function (req, res) {
// Create a session-store to be used by both the express-session
// middleware and the keycloak middleware.

var memoryStore = new session.MemoryStore();
const memoryStore = new session.MemoryStore();

app.use(session({
secret: 'mySecret',
Expand All @@ -56,7 +56,7 @@ app.use(session({
// Additional configuration is read from keycloak.json file
// installed from the Keycloak web console.

var keycloak = new Keycloak({
const keycloak = new Keycloak({
store: memoryStore
});

Expand Down
48 changes: 24 additions & 24 deletions keycloak.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@
* the License.
*/

var BearerStore = require('./stores/bearer-store');
var CookieStore = require('./stores/cookie-store');
var SessionStore = require('./stores/session-store');

var Config = require('./middleware/auth-utils/config');
var GrantManager = require('./middleware/auth-utils/grant-manager');
var Setup = require('./middleware/setup');
var Admin = require('./middleware/admin');
var Logout = require('./middleware/logout');
var PostAuth = require('./middleware/post-auth');
var GrantAttacher = require('./middleware/grant-attacher');
var Protect = require('./middleware/protect');
var Enforcer = require('./middleware/enforcer');
var CheckSso = require('./middleware/check-sso');
const BearerStore = require('./stores/bearer-store');
const CookieStore = require('./stores/cookie-store');
const SessionStore = require('./stores/session-store');

const Config = require('./middleware/auth-utils/config');
const GrantManager = require('./middleware/auth-utils/grant-manager');
const Setup = require('./middleware/setup');
const Admin = require('./middleware/admin');
const Logout = require('./middleware/logout');
const PostAuth = require('./middleware/post-auth');
const GrantAttacher = require('./middleware/grant-attacher');
const Protect = require('./middleware/protect');
const Enforcer = require('./middleware/enforcer');
const CheckSso = require('./middleware/check-sso');

/**
* Instantiate a Keycloak.
Expand Down Expand Up @@ -64,7 +64,7 @@ function Keycloak (config, keycloakConfig) {

this.grantManager = new GrantManager(this.config);

this.stores = [ BearerStore ];
this.stores = [BearerStore];

if (!config) {
throw new Error('Adapter configuration must be provided.');
Expand Down Expand Up @@ -115,7 +115,7 @@ Keycloak.prototype.middleware = function (options) {
options.logout = options.logout || '/logout';
options.admin = options.admin || '/';

var middlewares = [];
const middlewares = [];

middlewares.push(Setup);
middlewares.push(PostAuth(this));
Expand Down Expand Up @@ -305,23 +305,23 @@ Keycloak.prototype.accessDenied = function (request, response) {

/*! ignore */
Keycloak.prototype.getGrant = function (request, response) {
var rawData;
let rawData;

for (var i = 0; i < this.stores.length; ++i) {
for (let i = 0; i < this.stores.length; ++i) {
rawData = this.stores[i].get(request);
if (rawData) {
// store = this.stores[i];
break;
}
}

var grantData = rawData;
let grantData = rawData;
if (typeof (grantData) === 'string') {
grantData = JSON.parse(grantData);
}

if (grantData && !grantData.error) {
var self = this;
const self = this;
return this.grantManager.createGrant(JSON.stringify(grantData))
.then(grant => {
self.storeGrant(grant, request, response);
Expand Down Expand Up @@ -364,9 +364,9 @@ Keycloak.prototype.getGrantFromCode = function (code, request, response) {
throw new Error('Cannot exchange code for grant in bearer-only mode');
}

var sessionId = request.session.id;
const sessionId = request.session.id;

var self = this;
const self = this;
return this.grantManager.obtainFromCode(request, code, sessionId)
.then(function (grant) {
self.storeGrant(grant, request, response);
Expand All @@ -375,7 +375,7 @@ Keycloak.prototype.getGrantFromCode = function (code, request, response) {
};

Keycloak.prototype.checkPermissions = function (authzRequest, request, callback) {
var self = this;
const self = this;
return this.grantManager.checkPermissions(authzRequest, request, callback)
.then(function (grant) {
if (!authzRequest.response_mode) {
Expand All @@ -386,7 +386,7 @@ Keycloak.prototype.checkPermissions = function (authzRequest, request, callback)
};

Keycloak.prototype.loginUrl = function (uuid, redirectUrl) {
var url = this.config.realmUrl +
let url = this.config.realmUrl +
'/protocol/openid-connect/auth' +
'?client_id=' + encodeURIComponent(this.config.clientId) +
'&state=' + encodeURIComponent(uuid) +
Expand Down
18 changes: 9 additions & 9 deletions middleware/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
*/
'use strict';

var Token = require('./auth-utils/token');
var Signature = require('./auth-utils/signature');
const Token = require('./auth-utils/token');
const Signature = require('./auth-utils/signature');

function Admin (keycloak, url) {
this._keycloak = keycloak;
if (url[ url.length - 1 ] !== '/') {
if (url[url.length - 1] !== '/') {
url += '/;';
}
this._url = url + 'k_logout';
Expand All @@ -38,13 +38,13 @@ function adminLogout (request, response, keycloak) {
});

request.on('end', function () {
let token = new Token(data);
const token = new Token(data);
let signature;
try {
signature = new Signature(keycloak.config);
signature.verify(token).then(token => {
if (token.content.action === 'LOGOUT') {
let sessionIDs = token.content.adapterSessionIds;
const sessionIDs = token.content.adapterSessionIds;
if (!sessionIDs) {
keycloak.grantManager.notBefore = token.content.notBefore;
response.send('ok');
Expand Down Expand Up @@ -81,7 +81,7 @@ function adminNotBefore (request, response, keycloak) {
});

request.on('end', function () {
let token = new Token(data);
const token = new Token(data);
let signature;
try {
signature = new Signature(keycloak.config);
Expand All @@ -101,11 +101,11 @@ function adminNotBefore (request, response, keycloak) {

module.exports = function (keycloak, adminUrl) {
let url = adminUrl;
if (url[ url.length - 1 ] !== '/') {
if (url[url.length - 1] !== '/') {
url = url + '/';
}
let urlLogout = url + 'k_logout';
let urlNotBefore = url + 'k_push_not_before';
const urlLogout = url + 'k_logout';
const urlNotBefore = url + 'k_push_not_before';

return function adminRequest (request, response, next) {
switch (request.url) {
Expand Down
10 changes: 5 additions & 5 deletions middleware/auth-utils/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,17 @@ Config.prototype.configure = function configure (config) {
}

// "${env.MY_ENVIRONMENT_VARIABLE:http://localhost:8080}".replace(/\$\{env\.([^:]*):?(.*)?\}/,"$1--split--$2").split("--split--")
let regex = /\$\{env\.([^:]*):?(.*)?\}/;
const regex = /\$\{env\.([^:]*):?(.*)?\}/;

// is this an environment variable reference with potential fallback?
if (!regex.test(value)) {
return value;
}

let tokens = value.replace(regex, '$1--split--$2').split('--split--');
let envVar = tokens[0];
let envVal = process.env[envVar];
let fallbackVal = tokens[1];
const tokens = value.replace(regex, '$1--split--$2').split('--split--');
const envVar = tokens[0];
const envVal = process.env[envVar];
const fallbackVal = tokens[1];

return envVal || fallbackVal;
}
Expand Down
30 changes: 15 additions & 15 deletions middleware/auth-utils/grant-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const crypto = require('crypto');
const querystring = require('querystring');
const Grant = require('./grant');
const Token = require('./token');
var Rotation = require('./rotation');
const Rotation = require('./rotation');

/**
* Construct a grant manager.
Expand Down Expand Up @@ -131,7 +131,7 @@ GrantManager.prototype.checkPermissions = function obtainPermissions (authzReque
options.headers.Authorization = 'Bearer ' + request.kauth.grant.access_token.token;
}
} else {
let header = request.headers.authorization;
const header = request.headers.authorization;
let bearerToken;

if (header && (header.indexOf('bearer ') === 0 || header.indexOf('Bearer ') === 0)) {
Expand All @@ -156,14 +156,14 @@ GrantManager.prototype.checkPermissions = function obtainPermissions (authzReque
}

for (let i = 0; i < permissions.length; i++) {
var resource = permissions[i];
var permission = resource.id;
const resource = permissions[i];
let permission = resource.id;

if (resource.scopes && resource.scopes.length > 0) {
permission += '#';

for (let j = 0; j < resource.scopes.length; j++) {
var scope = resource.scopes[j];
const scope = resource.scopes[j];
if (permission.indexOf('#') !== permission.length - 1) {
permission += ',';
}
Expand All @@ -178,9 +178,9 @@ GrantManager.prototype.checkPermissions = function obtainPermissions (authzReque
params.permission.push(permission);
}

let manager = this;
const manager = this;

var handler = (resolve, reject, json) => {
const handler = (resolve, reject, json) => {
try {
if (authzRequest.response_mode === 'decision' || authzRequest.response_mode === 'permissions') {
callback(JSON.parse(json));
Expand Down Expand Up @@ -282,15 +282,15 @@ GrantManager.prototype.validateAccessToken = function validateAccessToken (token

GrantManager.prototype.userInfo = function userInfo (token, callback) {
const url = this.realmUrl + '/protocol/openid-connect/userinfo';
const options = URL.parse(url);
const options = URL.parse(url); // eslint-disable-line
options.method = 'GET';

let t = token;
if (typeof token === 'object') t = token.token;

options.headers = {
'Authorization': 'Bearer ' + t,
'Accept': 'application/json',
Authorization: 'Bearer ' + t,
Accept: 'application/json',
'X-Client': 'keycloak-nodejs-connect'
};

Expand Down Expand Up @@ -373,7 +373,7 @@ GrantManager.prototype.createGrant = function createGrant (rawData) {
* rejects with an error if any of the tokens are invalid.
*/
GrantManager.prototype.validateGrant = function validateGrant (grant) {
var self = this;
const self = this;
const validateGrantToken = (grant, tokenName, expectedType) => {
return new Promise((resolve, reject) => {
// check the access token
Expand All @@ -386,7 +386,7 @@ GrantManager.prototype.validateGrant = function validateGrant (grant) {
});
};
return new Promise((resolve, reject) => {
var promises = [];
const promises = [];
promises.push(validateGrantToken(grant, 'access_token', 'Bearer'));
if (!self.bearerOnly) {
if (grant.id_token) {
Expand Down Expand Up @@ -427,7 +427,7 @@ GrantManager.prototype.validateToken = function validateToken (token, expectedTy
} else if (token.content.iss !== this.realmUrl) {
reject(new Error('invalid token (wrong ISS)'));
} else {
var audienceData = Array.isArray(token.content.aud) ? token.content.aud : [token.content.aud];
const audienceData = Array.isArray(token.content.aud) ? token.content.aud : [token.content.aud];
if (expectedType === 'ID') {
if (!audienceData.includes(this.clientId)) {
reject(new Error('invalid token (wrong audience)'));
Expand Down Expand Up @@ -501,7 +501,7 @@ const validationHandler = (manager, token) => (resolve, reject, json) => {

const postOptions = (manager, path) => {
const realPath = path || '/protocol/openid-connect/token';
const opts = URL.parse(manager.realmUrl + realPath);
const opts = URL.parse(manager.realmUrl + realPath); // eslint-disable-line
opts.headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'X-Client': 'keycloak-nodejs-connect'
Expand All @@ -520,7 +520,7 @@ const fetch = (manager, handler, options, params) => {

const req = getProtocol(options).request(options, (response) => {
if (response.statusCode < 200 || response.statusCode > 299) {
return reject(new Error(response.statusCode + ':' + http.STATUS_CODES[ response.statusCode ]));
return reject(new Error(response.statusCode + ':' + http.STATUS_CODES[response.statusCode]));
}
let json = '';
response.on('data', (d) => (json += d.toString()));
Expand Down
10 changes: 5 additions & 5 deletions middleware/auth-utils/rotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function Rotation (config) {

Rotation.prototype.retrieveJWKs = function retrieveJWKs (callback) {
const url = this.realmUrl + '/protocol/openid-connect/certs';
const options = URL.parse(url);
const options = URL.parse(url); // eslint-disable-line
options.method = 'GET';
const promise = new Promise((resolve, reject) => {
const req = getProtocol(options).request(options, (response) => {
Expand All @@ -57,22 +57,22 @@ Rotation.prototype.retrieveJWKs = function retrieveJWKs (callback) {
};

Rotation.prototype.getJWK = function getJWK (kid) {
let key = this.jwks.find((key) => { return key.kid === kid; });
const key = this.jwks.find((key) => { return key.kid === kid; });
if (key) {
return new Promise((resolve, reject) => {
resolve(jwkToPem(key));
});
}
var self = this;
const self = this;

// check if we are allowed to send request
var currentTime = new Date().getTime() / 1000;
const currentTime = new Date().getTime() / 1000;
if (currentTime > this.lastTimeRequesTime + this.minTimeBetweenJwksRequests) {
return this.retrieveJWKs()
.then(publicKeys => {
self.lastTimeRequesTime = currentTime;
self.jwks = publicKeys.keys;
var convertedKey = jwkToPem(self.jwks.find((key) => { return key.kid === kid; }));
const convertedKey = jwkToPem(self.jwks.find((key) => { return key.kid === kid; }));
return convertedKey;
});
} else {
Expand Down
Loading

0 comments on commit 45d15d6

Please sign in to comment.