New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

keycloak-nodejs-middleware

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

keycloak-nodejs-middleware - npm Package Compare versions

Comparing version 1.4.0 to 1.5.0

122

dist/cjs/index.js
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -61,5 +38,9 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }

};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.keycloakMiddleware = void 0;
var node_fetch_commonjs_1 = __importStar(require("node-fetch-commonjs"));
var https_1 = __importDefault(require("https"));
var url_1 = require("url");
function keycloakMiddleware(_a) {

@@ -69,51 +50,54 @@ var _this = this;

return function (request, response, next) { return __awaiter(_this, void 0, void 0, function () {
var myHeaders, urlencoded, token, requestOptions, url, rawResponse, body, error_1;
var url, token, data, requestOptions, req;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!request.headers.authorization) return [3 /*break*/, 6];
_a.label = 1;
case 1:
_a.trys.push([1, 4, , 5]);
myHeaders = new node_fetch_commonjs_1.Headers();
myHeaders.append("Content-Type", "application/x-www-form-urlencoded");
urlencoded = new URLSearchParams();
urlencoded.append("client_id", client_id);
urlencoded.append("grant_type", "password");
urlencoded.append("client_secret", client_secret);
urlencoded.append("scope", "openid");
// assumes bearer token is passed as an authorization header
if (request.headers.authorization) {
try {
url = "".concat(host, "/realms/").concat(realm, "/protocol/openid-connect/token/introspect");
token = request.headers.authorization.replace("Bearer ", "");
urlencoded.append("token", token);
data = new url_1.URLSearchParams();
data.append("client_id", client_id);
data.append("grant_type", "password");
data.append("client_secret", client_secret);
data.append("scope", "openid");
data.append("token", token);
requestOptions = {
method: "POST",
headers: myHeaders,
body: urlencoded,
redirect: "follow",
strictSSL: false,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
};
url = "".concat(host, "/realms/").concat(realm, "/protocol/openid-connect/token/introspect");
return [4 /*yield*/, (0, node_fetch_commonjs_1.default)(url, requestOptions)];
case 2:
rawResponse = _a.sent();
return [4 /*yield*/, rawResponse.text()];
case 3:
body = _a.sent();
body = JSON.parse(body);
if (body.hasOwnProperty("active") && body.active === false) {
return [2 /*return*/, response.status(401).json({
error: true,
message: "Unauthorized",
})];
}
else {
// the token is valid pass request onto your next function
next();
}
return [3 /*break*/, 5];
case 4:
error_1 = _a.sent();
next(error_1);
return [3 /*break*/, 5];
case 5: return [3 /*break*/, 7];
case 6:
req = https_1.default.request(url, requestOptions, function (res) {
var body = "";
res.on("data", function (chunk) {
body += chunk;
});
res.on("end", function () {
try {
var parsedBody = JSON.parse(body);
if (parsedBody.hasOwnProperty("active") &&
parsedBody.active === false) {
return response.status(401).json({
error: true,
message: "Unauthorized",
});
}
else {
// the token is valid pass request onto your next function
next();
}
}
catch (error) {
next(error);
}
});
});
req.write(data.toString());
req.end();
}
catch (error) {
next(error);
}
}
else {
// there is no token, don't process request further

@@ -124,4 +108,4 @@ return [2 /*return*/, response.status(401).json({

})];
case 7: return [2 /*return*/];
}
return [2 /*return*/];
});

@@ -128,0 +112,0 @@ }); };

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -61,5 +38,9 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }

};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.keycloakMiddleware = void 0;
var node_fetch_commonjs_1 = __importStar(require("node-fetch-commonjs"));
var https_1 = __importDefault(require("https"));
var url_1 = require("url");
function keycloakMiddleware(_a) {

@@ -69,51 +50,54 @@ var _this = this;

return function (request, response, next) { return __awaiter(_this, void 0, void 0, function () {
var myHeaders, urlencoded, token, requestOptions, url, rawResponse, body, error_1;
var url, token, data, requestOptions, req;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!request.headers.authorization) return [3 /*break*/, 6];
_a.label = 1;
case 1:
_a.trys.push([1, 4, , 5]);
myHeaders = new node_fetch_commonjs_1.Headers();
myHeaders.append("Content-Type", "application/x-www-form-urlencoded");
urlencoded = new URLSearchParams();
urlencoded.append("client_id", client_id);
urlencoded.append("grant_type", "password");
urlencoded.append("client_secret", client_secret);
urlencoded.append("scope", "openid");
// assumes bearer token is passed as an authorization header
if (request.headers.authorization) {
try {
url = "".concat(host, "/realms/").concat(realm, "/protocol/openid-connect/token/introspect");
token = request.headers.authorization.replace("Bearer ", "");
urlencoded.append("token", token);
data = new url_1.URLSearchParams();
data.append("client_id", client_id);
data.append("grant_type", "password");
data.append("client_secret", client_secret);
data.append("scope", "openid");
data.append("token", token);
requestOptions = {
method: "POST",
headers: myHeaders,
body: urlencoded,
redirect: "follow",
strictSSL: false,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
};
url = "".concat(host, "/realms/").concat(realm, "/protocol/openid-connect/token/introspect");
return [4 /*yield*/, (0, node_fetch_commonjs_1.default)(url, requestOptions)];
case 2:
rawResponse = _a.sent();
return [4 /*yield*/, rawResponse.text()];
case 3:
body = _a.sent();
body = JSON.parse(body);
if (body.hasOwnProperty("active") && body.active === false) {
return [2 /*return*/, response.status(401).json({
error: true,
message: "Unauthorized",
})];
}
else {
// the token is valid pass request onto your next function
next();
}
return [3 /*break*/, 5];
case 4:
error_1 = _a.sent();
next(error_1);
return [3 /*break*/, 5];
case 5: return [3 /*break*/, 7];
case 6:
req = https_1.default.request(url, requestOptions, function (res) {
var body = "";
res.on("data", function (chunk) {
body += chunk;
});
res.on("end", function () {
try {
var parsedBody = JSON.parse(body);
if (parsedBody.hasOwnProperty("active") &&
parsedBody.active === false) {
return response.status(401).json({
error: true,
message: "Unauthorized",
});
}
else {
// the token is valid pass request onto your next function
next();
}
}
catch (error) {
next(error);
}
});
});
req.write(data.toString());
req.end();
}
catch (error) {
next(error);
}
}
else {
// there is no token, don't process request further

@@ -124,4 +108,4 @@ return [2 /*return*/, response.status(401).json({

})];
case 7: return [2 /*return*/];
}
return [2 /*return*/];
});

@@ -128,0 +112,0 @@ }); };

{
"name": "keycloak-nodejs-middleware",
"version": "1.4.0",
"version": "1.5.0",
"description": "Keycloak middleware for nodejs apps",

@@ -5,0 +5,0 @@ "main": "./dist/cjs/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc