@yrpri/api 9.0.131 → 9.0.133

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/app.js CHANGED
@@ -486,6 +486,7 @@ export class YourPrioritiesApi {
486
486
  this.app.use((req, res, next) => {
487
487
  if (req.url.indexOf("/auth") > -1 ||
488
488
  req.url.indexOf("/login") > -1 ||
489
+ req.url.indexOf("/logout") > -1 ||
489
490
  req.url.indexOf("saml_assertion") > -1) {
490
491
  sso.init(req.ypDomain?.loginHosts, req.ypDomain?.loginProviders, {
491
492
  authorize: this.bearerCallback,
@@ -15,20 +15,35 @@ const randomstring = require('randomstring');
15
15
  const { sendPlausibleFavicon } = require("../services/engine/analytics/plausible/manager.cjs");
16
16
  var getAllModeratedItemsByUser = require('../services/engine/moderation/get_moderation_items.cjs').getAllModeratedItemsByUser;
17
17
  const performSingleModerationAction = require('../services/engine/moderation/process_moderation_items.cjs').performSingleModerationAction;
18
- const logoutFromSession = (req, res, statusCode = 200) => {
18
+ const logoutFromSession = (req, res, statusCode = 200, callback) => {
19
19
  if (req.session) {
20
20
  req.session.destroy((err) => {
21
21
  if (err) {
22
22
  log.error("Error on destroying session", { err });
23
- return res.sendStatus(500);
23
+ if (!callback) {
24
+ return res.sendStatus(500);
25
+ }
26
+ else {
27
+ return callback(err);
28
+ }
24
29
  }
25
30
  res.clearCookie('yrpri.sid', { path: '/' });
26
31
  log.info("Session destroyed successfully");
27
- res.sendStatus(statusCode);
32
+ if (callback) {
33
+ callback();
34
+ }
35
+ else {
36
+ res.sendStatus(statusCode);
37
+ }
28
38
  });
29
39
  }
30
40
  else {
31
- res.sendStatus(statusCode);
41
+ if (callback) {
42
+ callback();
43
+ }
44
+ else {
45
+ res.sendStatus(statusCode);
46
+ }
32
47
  }
33
48
  };
34
49
  var sendUserOrError = function (res, user, context, error, errorStatus) {
@@ -1429,7 +1444,22 @@ router.post('/logout', function (req, res) {
1429
1444
  else {
1430
1445
  log.warn('User Logging out but not logged in', { context: 'logout' });
1431
1446
  }
1432
- logoutFromSession(req, res);
1447
+ const oidcProvider = req.ypDomain &&
1448
+ req.ypDomain.loginProviders &&
1449
+ req.ypDomain.loginProviders.find((p) => p.provider === 'oidc');
1450
+ if (req.sso && oidcProvider && oidcProvider.endSessionURL) {
1451
+ logoutFromSession(req, res, 200, () => {
1452
+ req.sso.logout(oidcProvider.name, { postLogoutRedirectUri: '/' }, req, res, (error) => {
1453
+ if (error) {
1454
+ log.error('Error logging out from OIDC', { err: error });
1455
+ res.sendStatus(500);
1456
+ }
1457
+ });
1458
+ });
1459
+ }
1460
+ else {
1461
+ logoutFromSession(req, res);
1462
+ }
1433
1463
  });
1434
1464
  // Reset password
1435
1465
  router.post('/forgot_password', function (req, res) {
package/models/domain.cjs CHANGED
@@ -337,6 +337,7 @@ module.exports = (sequelize, DataTypes) => {
337
337
  req.ypDomain = domain;
338
338
  if (req.url.indexOf("/auth") > -1 ||
339
339
  req.url.indexOf("/login") > -1 ||
340
+ req.url.indexOf("/logout") > -1 ||
340
341
  req.url.indexOf("saml_assertion") > -1) {
341
342
  sequelize.models.Domain.getLoginProviders(req, domain, (error, providers) => {
342
343
  req.ypDomain.loginProviders = providers;
@@ -363,6 +364,7 @@ module.exports = (sequelize, DataTypes) => {
363
364
  req.ypDomain = domain;
364
365
  if (req.url.indexOf("/auth") > -1 ||
365
366
  req.url.indexOf("/login") > -1 ||
367
+ req.url.indexOf("/logout") > -1 ||
366
368
  req.url.indexOf("saml_assertion") > -1) {
367
369
  sequelize.models.Domain.getLoginProviders(req, domain, (error, providers) => {
368
370
  log.info("Login Providers", { providers });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yrpri/api",
3
- "version": "9.0.131",
3
+ "version": "9.0.133",
4
4
  "license": "MIT",
5
5
  "author": "Robert Bjarnason & Citizens Foundation",
6
6
  "repository": {
@@ -77,7 +77,7 @@
77
77
  "passport-local": "^1.0.0",
78
78
  "passport-openidconnect": "git+https://github.com/rbjarnason/passport-openidconnect.git",
79
79
  "passport-saml": "git+https://github.com/rbjarnason/passport-saml.git#smarternj",
80
- "passport-sso": "git+https://github.com/rbjarnason/passport-sso.git#master",
80
+ "passport-sso": "github:rbjarnason/passport-sso",
81
81
  "pug": "^3.0.3",
82
82
  "randomstring": "^1.3.1",
83
83
  "rate-limit-redis": "^4.2.0",