kopi-id
Version:
Simple OIDC Library
175 lines (141 loc) • 6.03 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _jwt = _interopRequireDefault(require("./jwt"));
var _logger = _interopRequireDefault(require("./logger"));
var _hash = _interopRequireDefault(require("./hash"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
var _default = function _default(oidcConfig) {
var _loggerService = (0, _logger["default"])('Validation Service', oidcConfig.logLevel),
L = _loggerService.L;
var jwtService = (0, _jwt["default"])(oidcConfig);
var validateAuthorizationCode = /*#__PURE__*/function () {
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(authorizationCode) {
var authorizationRequest;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.prev = 0;
_context.next = 3;
return oidcConfig.onLoadAuthorization(authorizationCode);
case 3:
authorizationRequest = _context.sent;
if (!(authorizationRequest == null)) {
_context.next = 6;
break;
}
return _context.abrupt("return", Promise.resolve(null));
case 6:
_context.next = 8;
return oidcConfig.onRevokeAuthorization(authorizationCode);
case 8:
return _context.abrupt("return", Promise.resolve(authorizationRequest));
case 11:
_context.prev = 11;
_context.t0 = _context["catch"](0);
return _context.abrupt("return", Promise.reject(_context.t0));
case 14:
case "end":
return _context.stop();
}
}
}, _callee, null, [[0, 11]]);
}));
return function validateAuthorizationCode(_x) {
return _ref.apply(this, arguments);
};
}();
var validateIdToken = /*#__PURE__*/function () {
var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(idToken, client) {
var payload;
return regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.prev = 0;
payload = jwtService.verifyIdToken(idToken, client);
return _context2.abrupt("return", Promise.resolve(payload));
case 5:
_context2.prev = 5;
_context2.t0 = _context2["catch"](0);
return _context2.abrupt("return", Promise.reject(_context2.t0));
case 8:
case "end":
return _context2.stop();
}
}
}, _callee2, null, [[0, 5]]);
}));
return function validateIdToken(_x2, _x3) {
return _ref2.apply(this, arguments);
};
}();
var validateToken = /*#__PURE__*/function () {
var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(token, accessTokenSecret) {
var payload;
return regeneratorRuntime.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
_context3.prev = 0;
_context3.next = 3;
return jwtService.verifyToken(token, accessTokenSecret);
case 3:
payload = _context3.sent;
return _context3.abrupt("return", Promise.resolve(payload));
case 7:
_context3.prev = 7;
_context3.t0 = _context3["catch"](0);
return _context3.abrupt("return", Promise.reject(_context3.t0));
case 10:
case "end":
return _context3.stop();
}
}
}, _callee3, null, [[0, 7]]);
}));
return function validateToken(_x4, _x5) {
return _ref3.apply(this, arguments);
};
}();
var validateClientSecretJwt = /*#__PURE__*/function () {
var _ref4 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4(token) {
var payload;
return regeneratorRuntime.wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
_context4.prev = 0;
_context4.next = 3;
return jwtService.validateClientSecretJwt(token);
case 3:
payload = _context4.sent;
return _context4.abrupt("return", Promise.resolve(payload.sub));
case 7:
_context4.prev = 7;
_context4.t0 = _context4["catch"](0);
return _context4.abrupt("return", Promise.reject(_context4.t0));
case 10:
case "end":
return _context4.stop();
}
}
}, _callee4, null, [[0, 7]]);
}));
return function validateClientSecretJwt(_x6) {
return _ref4.apply(this, arguments);
};
}();
return {
validateAuthorizationCode: validateAuthorizationCode,
validateIdToken: validateIdToken,
validateToken: validateToken,
validateClientSecretJwt: validateClientSecretJwt
};
};
exports["default"] = _default;