@hmcts/opal-frontend-common-node 0.0.12 → 0.0.13

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.
Files changed (81) hide show
  1. package/interfaces/index.d.ts +1 -2
  2. package/interfaces/index.d.ts.map +1 -1
  3. package/interfaces/index.js +1 -2
  4. package/interfaces/index.js.map +1 -1
  5. package/interfaces/routes-config.d.ts +5 -0
  6. package/interfaces/routes-config.d.ts.map +1 -1
  7. package/interfaces/routes-config.js +5 -0
  8. package/interfaces/routes-config.js.map +1 -1
  9. package/interfaces/securityToken.d.ts +1 -2
  10. package/interfaces/securityToken.d.ts.map +1 -1
  11. package/interfaces/securityToken.js.map +1 -1
  12. package/interfaces/session-config.d.ts +0 -1
  13. package/interfaces/session-config.d.ts.map +1 -1
  14. package/interfaces/session-config.js +0 -1
  15. package/interfaces/session-config.js.map +1 -1
  16. package/package.json +4 -3
  17. package/routes/index.d.ts +1 -0
  18. package/routes/index.d.ts.map +1 -1
  19. package/routes/index.js +38 -23
  20. package/routes/index.js.map +1 -1
  21. package/session/index.d.ts +1 -2
  22. package/session/index.d.ts.map +1 -1
  23. package/session/index.js +1 -2
  24. package/session/index.js.map +1 -1
  25. package/session.d.ts +2 -2
  26. package/sso/index.d.ts +2 -2
  27. package/sso/index.d.ts.map +1 -1
  28. package/sso/index.js +2 -2
  29. package/sso/index.js.map +1 -1
  30. package/sso/sso-authenticated.d.ts +10 -0
  31. package/sso/sso-authenticated.d.ts.map +1 -1
  32. package/sso/sso-authenticated.js +17 -5
  33. package/sso/sso-authenticated.js.map +1 -1
  34. package/sso/sso-configuration.d.ts +12 -0
  35. package/sso/sso-configuration.d.ts.map +1 -0
  36. package/sso/sso-configuration.js +44 -0
  37. package/sso/sso-configuration.js.map +1 -0
  38. package/sso/sso-login-callback.d.ts +21 -3
  39. package/sso/sso-login-callback.d.ts.map +1 -1
  40. package/sso/sso-login-callback.js +72 -19
  41. package/sso/sso-login-callback.js.map +1 -1
  42. package/sso/sso-login.d.ts +17 -2
  43. package/sso/sso-login.d.ts.map +1 -1
  44. package/sso/sso-login.js +24 -17
  45. package/sso/sso-login.js.map +1 -1
  46. package/sso/sso-logout-callback.d.ts +10 -0
  47. package/sso/sso-logout-callback.d.ts.map +1 -1
  48. package/sso/sso-logout-callback.js +10 -0
  49. package/sso/sso-logout-callback.js.map +1 -1
  50. package/sso/sso-logout.d.ts +14 -3
  51. package/sso/sso-logout.d.ts.map +1 -1
  52. package/sso/sso-logout.js +19 -25
  53. package/sso/sso-logout.js.map +1 -1
  54. package/stubs/sso/sso-authenticated.stub.d.ts +11 -0
  55. package/stubs/sso/sso-authenticated.stub.d.ts.map +1 -1
  56. package/stubs/sso/sso-authenticated.stub.js +14 -6
  57. package/stubs/sso/sso-authenticated.stub.js.map +1 -1
  58. package/stubs/sso/sso-login-callback.stub.d.ts +17 -0
  59. package/stubs/sso/sso-login-callback.stub.d.ts.map +1 -1
  60. package/stubs/sso/sso-login-callback.stub.js +38 -6
  61. package/stubs/sso/sso-login-callback.stub.js.map +1 -1
  62. package/stubs/sso/sso-login.stub.d.ts +11 -0
  63. package/stubs/sso/sso-login.stub.d.ts.map +1 -1
  64. package/stubs/sso/sso-login.stub.js +17 -8
  65. package/stubs/sso/sso-login.stub.js.map +1 -1
  66. package/stubs/sso/sso-logout-callback.stub.d.ts +12 -0
  67. package/stubs/sso/sso-logout-callback.stub.d.ts.map +1 -1
  68. package/stubs/sso/sso-logout-callback.stub.js +12 -0
  69. package/stubs/sso/sso-logout-callback.stub.js.map +1 -1
  70. package/stubs/sso/sso-logout.stub.d.ts +14 -2
  71. package/stubs/sso/sso-logout.stub.d.ts.map +1 -1
  72. package/stubs/sso/sso-logout.stub.js +21 -3
  73. package/stubs/sso/sso-logout.stub.js.map +1 -1
  74. package/interfaces/userState.d.ts +0 -16
  75. package/interfaces/userState.d.ts.map +0 -1
  76. package/interfaces/userState.js +0 -16
  77. package/interfaces/userState.js.map +0 -1
  78. package/session/session-user-state/index.d.ts +0 -4
  79. package/session/session-user-state/index.d.ts.map +0 -1
  80. package/session/session-user-state/index.js +0 -20
  81. package/session/session-user-state/index.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"sso-login-callback.js","sourceRoot":"","sources":["../../src/sso/sso-login-callback.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,eAAe,KAAK,EAAE,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,UAAkB,EAAE,EAAE;IAC3F,MAAM,sBAAsB,GAAG,GAAG,UAAU,kCAAkC,CAAC;IAC/E,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC;IAElD,IAAI,CAAC;QACH,8DAA8D;QAC9D,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,IAAI,CAAM,sBAAsB,EAAE,GAAG,CAAC,IAAI,EAAE;YACrE,OAAO,EAAE,EAAE,cAAc,EAAE,mCAAmC,EAAE;SACjE,CAAC,CAAC;QAEH,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC;QAClC,GAAG,CAAC,OAAO,CAAC,aAAa,GAAG,aAAa,CAAC;QAE1C,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE;YACvB,IAAI,GAAG,EAAE,CAAC;gBACR,MAAM,CAAC,KAAK,CAAC,sBAAsB,EAAE,GAAG,CAAC,CAAC;gBAC1C,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;YACnB,CAAC;YAED,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QACpB,CAAC,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,KAAK,CAAC,yBAAyB,EAAE,KAAK,CAAC,CAAC;QAC/C,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC;IACrB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AG,KAAa,EAAE,aAAa;SAC7C,CAAC,CAAC;QACH,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;IACpD,CAAC;AACH,CAAC"}
@@ -1,4 +1,19 @@
1
- import { NextFunction, Request, Response } from 'express';
2
- declare const _default: (req: Request, res: Response, next: NextFunction, opalApiUrl: string, frontendHostname: string) => Promise<void>;
1
+ import { NextFunction, Response } from 'express';
2
+ import { ConfidentialClientApplication } from '@azure/msal-node';
3
+ /**
4
+ * Initiates the SSO login process by generating an authorization code URL and redirecting the user.
5
+ *
6
+ * @param res - The Express response object used to redirect the user.
7
+ * @param next - The Express next middleware function for error handling.
8
+ * @param msalInstance - An instance of MSAL ConfidentialClientApplication used to generate the auth code URL.
9
+ * @param frontendHostname - The base URL of the frontend application.
10
+ * @param ssoLoginCallback - The callback path to be appended to the frontend hostname for redirection after login.
11
+ *
12
+ * @remarks
13
+ * This function constructs the authorization code URL with the required scopes and redirect URI,
14
+ * then redirects the user to the authentication provider. If an error occurs, it logs the error and
15
+ * passes it to the next middleware.
16
+ */
17
+ declare const _default: (res: Response, next: NextFunction, msalInstance: ConfidentialClientApplication, frontendHostname: string, ssoLoginCallback: string) => Promise<void>;
3
18
  export default _default;
4
19
  //# sourceMappingURL=sso-login.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sso-login.d.ts","sourceRoot":"","sources":["../../src/sso/sso-login.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;yBAKxD,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,MAAM,YAAY,EAClB,YAAY,MAAM,EAClB,kBAAkB,MAAM;AAL1B,wBA0BE"}
1
+ {"version":3,"file":"sso-login.d.ts","sourceRoot":"","sources":["../../src/sso/sso-login.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEjD,OAAO,EAAE,6BAA6B,EAAE,MAAM,kBAAkB,CAAC;AAEjE;;;;;;;;;;;;;GAaG;yBAED,KAAK,QAAQ,EACb,MAAM,YAAY,EAClB,cAAc,6BAA6B,EAC3C,kBAAkB,MAAM,EACxB,kBAAkB,MAAM;AAL1B,wBAoBE"}
package/sso/sso-login.js CHANGED
@@ -1,24 +1,31 @@
1
1
  import { Logger } from '@hmcts/nodejs-logging';
2
- import axios from 'axios';
3
- export default async (req, res, next, opalApiUrl, frontendHostname) => {
4
- const INTERNAL_USER_LOGIN = `${opalApiUrl}/internal-user/login-or-refresh`;
5
- const logger = Logger.getLogger('login');
6
- const url = `${INTERNAL_USER_LOGIN}?redirect_uri=${frontendHostname}/sso/login-callback`;
2
+ /**
3
+ * Initiates the SSO login process by generating an authorization code URL and redirecting the user.
4
+ *
5
+ * @param res - The Express response object used to redirect the user.
6
+ * @param next - The Express next middleware function for error handling.
7
+ * @param msalInstance - An instance of MSAL ConfidentialClientApplication used to generate the auth code URL.
8
+ * @param frontendHostname - The base URL of the frontend application.
9
+ * @param ssoLoginCallback - The callback path to be appended to the frontend hostname for redirection after login.
10
+ *
11
+ * @remarks
12
+ * This function constructs the authorization code URL with the required scopes and redirect URI,
13
+ * then redirects the user to the authentication provider. If an error occurs, it logs the error and
14
+ * passes it to the next middleware.
15
+ */
16
+ export default async (res, next, msalInstance, frontendHostname, ssoLoginCallback) => {
17
+ const logger = Logger.getLogger('sso-login');
7
18
  try {
8
- const response = await axios.get(url);
9
- const redirectUrl = response.request.res.responseUrl;
10
- if (redirectUrl) {
11
- res.redirect(redirectUrl);
12
- }
13
- else {
14
- const error = new Error('Error trying to fetch login page');
15
- logger.error('Error on login', error);
16
- return next(error);
17
- }
19
+ const authCodeUrl = await msalInstance.getAuthCodeUrl({
20
+ scopes: ['user.read'],
21
+ redirectUri: `${frontendHostname}${ssoLoginCallback}`,
22
+ responseMode: 'form_post',
23
+ });
24
+ res.redirect(authCodeUrl);
18
25
  }
19
26
  catch (error) {
20
- logger.error('Error on login', error);
21
- return next(error);
27
+ logger.error('Error on SSO Login:', error);
28
+ next(error);
22
29
  }
23
30
  };
24
31
  //# sourceMappingURL=sso-login.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"sso-login.js","sourceRoot":"","sources":["../../src/sso/sso-login.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,eAAe,KAAK,EAClB,GAAY,EACZ,GAAa,EACb,IAAkB,EAClB,UAAkB,EAClB,gBAAwB,EACxB,EAAE;IACF,MAAM,mBAAmB,GAAG,GAAG,UAAU,iCAAiC,CAAC;IAC3E,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IACzC,MAAM,GAAG,GAAG,GAAG,mBAAmB,iBAAiB,gBAAgB,qBAAqB,CAAC;IAEzF,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACtC,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;QAErD,IAAI,WAAW,EAAE,CAAC;YAChB,GAAG,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;QAC5B,CAAC;aAAM,CAAC;YACN,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;YAC5D,MAAM,CAAC,KAAK,CAAC,gBAAgB,EAAE,KAAK,CAAC,CAAC;YACtC,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC;QACrB,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,KAAK,CAAC,gBAAgB,EAAE,KAAK,CAAC,CAAC;QACtC,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;AACH,CAAC,CAAC"}
1
+ {"version":3,"file":"sso-login.js","sourceRoot":"","sources":["../../src/sso/sso-login.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAG/C;;;;;;;;;;;;;GAaG;AACH,eAAe,KAAK,EAClB,GAAa,EACb,IAAkB,EAClB,YAA2C,EAC3C,gBAAwB,EACxB,gBAAwB,EACxB,EAAE;IACF,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAC7C,IAAI,CAAC;QACH,MAAM,WAAW,GAAG,MAAM,YAAY,CAAC,cAAc,CAAC;YACpD,MAAM,EAAE,CAAC,WAAW,CAAC;YACrB,WAAW,EAAE,GAAG,gBAAgB,GAAG,gBAAgB,EAAE;YACrD,YAAY,EAAE,WAAW;SAC1B,CAAC,CAAC;QAEH,GAAG,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IAC5B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,KAAK,CAAC,qBAAqB,EAAE,KAAK,CAAC,CAAC;QAC3C,IAAI,CAAC,KAAK,CAAC,CAAC;IACd,CAAC;AACH,CAAC,CAAC"}
@@ -1,4 +1,14 @@
1
1
  import { NextFunction, Request, Response } from 'express';
2
+ /**
3
+ * Express middleware to handle SSO logout callback.
4
+ *
5
+ * Destroys the user's session, clears the authentication cookie, and redirects to the home page.
6
+ *
7
+ * @param req - Express request object.
8
+ * @param res - Express response object.
9
+ * @param next - Express next middleware function.
10
+ * @param prefix - The name of the cookie to clear.
11
+ */
2
12
  declare const _default: (req: Request, res: Response, next: NextFunction, prefix: string) => void;
3
13
  export default _default;
4
14
  //# sourceMappingURL=sso-logout-callback.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sso-logout-callback.d.ts","sourceRoot":"","sources":["../../src/sso/sso-logout-callback.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;yBAK1C,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,EAAE,QAAQ,MAAM;AAA/E,wBAWE"}
1
+ {"version":3,"file":"sso-logout-callback.d.ts","sourceRoot":"","sources":["../../src/sso/sso-logout-callback.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAK1D;;;;;;;;;GASG;yBACa,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,EAAE,QAAQ,MAAM;AAA/E,wBAWE"}
@@ -1,5 +1,15 @@
1
1
  import { Logger } from '@hmcts/nodejs-logging';
2
2
  const logger = Logger.getLogger('logout');
3
+ /**
4
+ * Express middleware to handle SSO logout callback.
5
+ *
6
+ * Destroys the user's session, clears the authentication cookie, and redirects to the home page.
7
+ *
8
+ * @param req - Express request object.
9
+ * @param res - Express response object.
10
+ * @param next - Express next middleware function.
11
+ * @param prefix - The name of the cookie to clear.
12
+ */
3
13
  export default (req, res, next, prefix) => {
4
14
  req.session.destroy((err) => {
5
15
  if (err) {
@@ -1 +1 @@
1
- {"version":3,"file":"sso-logout-callback.js","sourceRoot":"","sources":["../../src/sso/sso-logout-callback.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE/C,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;AAE1C,eAAe,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,MAAc,EAAE,EAAE;IACjF,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QAC1B,IAAI,GAAG,EAAE,CAAC;YACR,MAAM,CAAC,KAAK,CAAC,0BAA0B,EAAE,GAAG,CAAC,CAAC;YAC9C,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC;QAED,GAAG,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAExB,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;IACpB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}
1
+ {"version":3,"file":"sso-logout-callback.js","sourceRoot":"","sources":["../../src/sso/sso-logout-callback.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE/C,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;AAE1C;;;;;;;;;GASG;AACH,eAAe,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,MAAc,EAAE,EAAE;IACjF,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QAC1B,IAAI,GAAG,EAAE,CAAC;YACR,MAAM,CAAC,KAAK,CAAC,0BAA0B,EAAE,GAAG,CAAC,CAAC;YAC9C,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC;QAED,GAAG,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAExB,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;IACpB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}
@@ -1,4 +1,15 @@
1
- import { NextFunction, Request, Response } from 'express';
2
- declare const _default: (req: Request, res: Response, next: NextFunction, opalApiUrl: string, frontendHostname: string) => Promise<void>;
3
- export default _default;
1
+ import { Response } from 'express';
2
+ /**
3
+ * Logs out the user from Microsoft SSO by redirecting to the Azure logout endpoint.
4
+ *
5
+ * Constructs the Azure logout URL using the provided Microsoft URL with tenant ID and
6
+ * the post-logout redirect URI, then redirects the response to this URL.
7
+ * If an error occurs during the process, logs the error and sends a 500 response.
8
+ *
9
+ * @param res - The HTTP response object used to perform the redirect.
10
+ * @param microsoftUrlWithTenantId - The base Microsoft URL including the tenant ID.
11
+ * @param ssoLogoutCallback - The URI to redirect to after logout is complete.
12
+ * @returns A promise that resolves when the logout process is complete.
13
+ */
14
+ export default function ssoLogout(res: Response, microsoftUrlWithTenantId: string, ssoLogoutCallback: string): Promise<void>;
4
15
  //# sourceMappingURL=sso-logout.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sso-logout.d.ts","sourceRoot":"","sources":["../../src/sso/sso-logout.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;yBAIxD,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,MAAM,YAAY,EAClB,YAAY,MAAM,EAClB,kBAAkB,MAAM;AAL1B,wBAoCE"}
1
+ {"version":3,"file":"sso-logout.d.ts","sourceRoot":"","sources":["../../src/sso/sso-logout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAGnC;;;;;;;;;;;GAWG;AACH,wBAA8B,SAAS,CACrC,GAAG,EAAE,QAAQ,EACb,wBAAwB,EAAE,MAAM,EAChC,iBAAiB,EAAE,MAAM,GACxB,OAAO,CAAC,IAAI,CAAC,CAWf"}
package/sso/sso-logout.js CHANGED
@@ -1,31 +1,25 @@
1
- import axios from 'axios';
2
1
  import { Logger } from '@hmcts/nodejs-logging';
3
- export default async (req, res, next, opalApiUrl, frontendHostname) => {
4
- const INTERNAL_USER_LOGOUT = `${opalApiUrl}/internal-user/logout`;
5
- const logger = Logger.getLogger('login');
6
- const url = `${INTERNAL_USER_LOGOUT}?redirect_uri=${frontendHostname}/sso/logout-callback`;
2
+ /**
3
+ * Logs out the user from Microsoft SSO by redirecting to the Azure logout endpoint.
4
+ *
5
+ * Constructs the Azure logout URL using the provided Microsoft URL with tenant ID and
6
+ * the post-logout redirect URI, then redirects the response to this URL.
7
+ * If an error occurs during the process, logs the error and sends a 500 response.
8
+ *
9
+ * @param res - The HTTP response object used to perform the redirect.
10
+ * @param microsoftUrlWithTenantId - The base Microsoft URL including the tenant ID.
11
+ * @param ssoLogoutCallback - The URI to redirect to after logout is complete.
12
+ * @returns A promise that resolves when the logout process is complete.
13
+ */
14
+ export default async function ssoLogout(res, microsoftUrlWithTenantId, ssoLogoutCallback) {
15
+ const logger = Logger.getLogger('sso-logout');
7
16
  try {
8
- let accessToken;
9
- if (req.session.securityToken) {
10
- accessToken = req.session.securityToken.access_token;
11
- }
12
- if (!accessToken) {
13
- return next(new Error('No access token found in session'));
14
- }
15
- const response = await axios.get(url, {
16
- headers: { Authorization: `Bearer ${accessToken}` },
17
- });
18
- const logoutRedirect = response.request.res.responseUrl;
19
- if (logoutRedirect) {
20
- res.redirect(logoutRedirect);
21
- }
22
- else {
23
- next(new Error('Error trying to fetch logout page'));
24
- }
17
+ const azureLogoutUrl = `${microsoftUrlWithTenantId}/oauth2/v2.0/logout?post_logout_redirect_uri=${ssoLogoutCallback}`;
18
+ res.redirect(azureLogoutUrl);
25
19
  }
26
20
  catch (error) {
27
- logger.error('Error logging out', error);
28
- return next(error);
21
+ logger.error('Error on SSO Logout:', error);
22
+ res.status(500).send('Logout failed');
29
23
  }
30
- };
24
+ }
31
25
  //# sourceMappingURL=sso-logout.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"sso-logout.js","sourceRoot":"","sources":["../../src/sso/sso-logout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE/C,eAAe,KAAK,EAClB,GAAY,EACZ,GAAa,EACb,IAAkB,EAClB,UAAkB,EAClB,gBAAwB,EACxB,EAAE;IACF,MAAM,oBAAoB,GAAG,GAAG,UAAU,uBAAuB,CAAC;IAClE,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IACzC,MAAM,GAAG,GAAG,GAAG,oBAAoB,iBAAiB,gBAAgB,sBAAsB,CAAC;IAE3F,IAAI,CAAC;QACH,IAAI,WAAW,CAAC;QAEhB,IAAI,GAAG,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC;YA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AAK,EAAE,CAAC;QACf,MAAM,CAAC,KAAK,CAAC,sBAAsB,EAAE,KAAK,CAAC,CAAC;QAC5C,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IACxC,CAAC;AACH,CAAC"}
@@ -1,4 +1,15 @@
1
1
  import { Request, Response } from 'express';
2
+ /**
3
+ * Express middleware that checks if the current session has a valid, non-expired access token.
4
+ *
5
+ * - Sets the `Cache-Control` header to prevent caching of the endpoint.
6
+ * - Retrieves the `access_token` from the session.
7
+ * - If the token is missing or expired (as determined by `Jwt.isJwtExpired`), responds with HTTP 401 and `false`.
8
+ * - Otherwise, responds with HTTP 200 and `true`.
9
+ *
10
+ * @param req - The Express request object, expected to have a `session.securityToken.access_token` property.
11
+ * @param res - The Express response object used to send the HTTP response.
12
+ */
2
13
  declare const _default: (req: Request, res: Response) => void;
3
14
  export default _default;
4
15
  //# sourceMappingURL=sso-authenticated.stub.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sso-authenticated.stub.d.ts","sourceRoot":"","sources":["../../../src/stubs/sso/sso-authenticated.stub.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;yBAG5B,KAAK,OAAO,EAAE,KAAK,QAAQ;AAA3C,wBAYE"}
1
+ {"version":3,"file":"sso-authenticated.stub.d.ts","sourceRoot":"","sources":["../../../src/stubs/sso/sso-authenticated.stub.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAG5C;;;;;;;;;;GAUG;yBACa,KAAK,OAAO,EAAE,KAAK,QAAQ;AAA3C,wBAWE"}
@@ -1,14 +1,22 @@
1
1
  import { Jwt } from '../../utils';
2
+ /**
3
+ * Express middleware that checks if the current session has a valid, non-expired access token.
4
+ *
5
+ * - Sets the `Cache-Control` header to prevent caching of the endpoint.
6
+ * - Retrieves the `access_token` from the session.
7
+ * - If the token is missing or expired (as determined by `Jwt.isJwtExpired`), responds with HTTP 401 and `false`.
8
+ * - Otherwise, responds with HTTP 200 and `true`.
9
+ *
10
+ * @param req - The Express request object, expected to have a `session.securityToken.access_token` property.
11
+ * @param res - The Express response object used to send the HTTP response.
12
+ */
2
13
  export default (req, res) => {
3
- const isJwtExpired = Jwt.isJwtExpired(req.session.securityToken?.access_token);
4
- const userId = req.session.securityToken?.user_state?.user_id;
5
14
  // Don't allow caching of this endpoint
6
15
  res.header('Cache-Control', 'no-store, must-revalidate');
7
- if (isJwtExpired || !userId) {
16
+ const accessToken = req.session.securityToken?.access_token;
17
+ if (!accessToken || Jwt.isJwtExpired(accessToken)) {
8
18
  res.status(401).send(false);
9
19
  }
10
- else {
11
- res.status(200).send(true);
12
- }
20
+ res.status(200).send(true);
13
21
  };
14
22
  //# sourceMappingURL=sso-authenticated.stub.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"sso-authenticated.stub.js","sourceRoot":"","sources":["../../../src/stubs/sso/sso-authenticated.stub.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAElC,eAAe,CAAC,GAAY,EAAE,GAAa,EAAE,EAAE;IAC7C,MAAM,YAAY,GAAG,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,aAAa,EAAE,YAAY,CAAC,CAAC;IAC/E,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC,aAAa,EAAE,UAAU,EAAE,OAAO,CAAC;IAE9D,uCAAuC;IACvC,GAAG,CAAC,MAAM,CAAC,eAAe,EAAE,2BAA2B,CAAC,CAAC;IAEzD,IAAI,YAAY,IAAI,CAAC,MAAM,EAAE,CAAC;QAC5B,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;SAAM,CAAC;QACN,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;AACH,CAAC,CAAC"}
1
+ {"version":3,"file":"sso-authenticated.stub.js","sourceRoot":"","sources":["../../../src/stubs/sso/sso-authenticated.stub.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAElC;;;;;;;;;;GAUG;AACH,eAAe,CAAC,GAAY,EAAE,GAAa,EAAE,EAAE;IAC7C,uCAAuC;IACvC,GAAG,CAAC,MAAM,CAAC,eAAe,EAAE,2BAA2B,CAAC,CAAC;IAEzD,MAAM,WAAW,GAAG,GAAG,CAAC,OAAO,CAAC,aAAa,EAAE,YAAY,CAAC;IAE5D,IAAI,CAAC,WAAW,IAAI,GAAG,CAAC,YAAY,CAAC,WAAW,CAAC,EAAE,CAAC;QAClD,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;IAED,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC7B,CAAC,CAAC"}
@@ -1,4 +1,21 @@
1
1
  import { NextFunction, Request, Response } from 'express';
2
+ /**
3
+ * Express middleware stub for handling SSO login callback in a testing environment.
4
+ *
5
+ * This middleware simulates the login callback by minting a JWT token for a supplied email address
6
+ * using the internal testing-support API. The token is then stored in the session for subsequent requests.
7
+ *
8
+ * @param req - Express request object, expects an 'email' query parameter.
9
+ * @param res - Express response object.
10
+ * @param next - Express next middleware function.
11
+ * @param opalApiUrl - The base URL of the Opal API, used to construct the token minting endpoint.
12
+ *
13
+ * @remarks
14
+ * - If the 'email' query parameter is missing, the middleware logs an error and calls `next` with the error.
15
+ * - If token minting fails or the response does not contain an access token, an error is logged and passed to `next`.
16
+ * - On success, the access token is stored in `req.session.securityToken` and the user is redirected to the root path.
17
+ * - Intended for use in test and development environments only.
18
+ */
2
19
  declare const _default: (req: Request, res: Response, next: NextFunction, opalApiUrl: string) => Promise<void>;
3
20
  export default _default;
4
21
  //# sourceMappingURL=sso-login-callback.stub.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sso-login-callback.stub.d.ts","sourceRoot":"","sources":["../../../src/stubs/sso/sso-login-callback.stub.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;yBAIpC,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,EAAE,YAAY,MAAM;AAAzF,wBAwBE"}
1
+ {"version":3,"file":"sso-login-callback.stub.d.ts","sourceRoot":"","sources":["../../../src/stubs/sso/sso-login-callback.stub.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAI1D;;;;;;;;;;;;;;;;GAgBG;yBACmB,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,EAAE,YAAY,MAAM;AAAzF,wBA2CE"}
@@ -1,21 +1,53 @@
1
1
  import { Logger } from '@hmcts/nodejs-logging';
2
2
  import axios from 'axios';
3
+ /**
4
+ * Express middleware stub for handling SSO login callback in a testing environment.
5
+ *
6
+ * This middleware simulates the login callback by minting a JWT token for a supplied email address
7
+ * using the internal testing-support API. The token is then stored in the session for subsequent requests.
8
+ *
9
+ * @param req - Express request object, expects an 'email' query parameter.
10
+ * @param res - Express response object.
11
+ * @param next - Express next middleware function.
12
+ * @param opalApiUrl - The base URL of the Opal API, used to construct the token minting endpoint.
13
+ *
14
+ * @remarks
15
+ * - If the 'email' query parameter is missing, the middleware logs an error and calls `next` with the error.
16
+ * - If token minting fails or the response does not contain an access token, an error is logged and passed to `next`.
17
+ * - On success, the access token is stored in `req.session.securityToken` and the user is redirected to the root path.
18
+ * - Intended for use in test and development environments only.
19
+ */
3
20
  export default async (req, res, next, opalApiUrl) => {
4
- const INTERNAL_JWT = `${opalApiUrl}/testing-support/token/user`;
5
21
  const logger = Logger.getLogger('login-callback-stub');
6
22
  try {
7
- const email = req.query['email'];
8
- const result = await axios.get(INTERNAL_JWT, {
23
+ const email = req.query['email']?.trim();
24
+ if (!email) {
25
+ const error = new Error('No email provided on login callback.');
26
+ logger.error(error);
27
+ return next(error);
28
+ }
29
+ const internalJwtUrl = `${opalApiUrl}/testing-support/token/user`;
30
+ // Ask testing-support to mint a token for the supplied email
31
+ const result = await axios.get(internalJwtUrl, {
9
32
  headers: { 'X-User-Email': email },
10
33
  });
11
- req.session.securityToken = result.data;
34
+ // testing-support may return just a JWT string or a structured token object
35
+ const data = result.data;
36
+ const access_token = typeof data === 'string' ? data : data?.access_token;
37
+ if (!access_token) {
38
+ const error = new Error('Token minting failed: missing access_token.');
39
+ logger.error(error, { data });
40
+ return next(error);
41
+ }
42
+ // Persist only what we need for subsequent calls
43
+ req.session.securityToken = { user_state: undefined, access_token };
12
44
  req.session.save((err) => {
13
45
  if (err) {
14
46
  logger.error('Error saving session', err);
15
47
  return next(err);
16
48
  }
17
- logger.info('Session saved');
18
- res.redirect('/');
49
+ logger.info('Session saved (access token only)');
50
+ return res.redirect('/');
19
51
  });
20
52
  }
21
53
  catch (error) {
@@ -1 +1 @@
1
- {"version":3,"file":"sso-login-callback.stub.js","sourceRoot":"","sources":["../../../src/stubs/sso/sso-login-callback.stub.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,eAAe,KAAK,EAAE,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,UAAkB,EAAE,EAAE;IAC3F,MAAM,YAAY,GAAG,GAAG,UAAU,6BAA6B,CAAC;IAChE,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,qBAAqB,CAAC,CAAC;IAEvD,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,CAAW,CAAC;QAC3C,MA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;QACf,MAAM,CAAC,KAAK,CAAC,8BAA8B,EAAE,KAAK,CAAC,CAAC;QACpD,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;AACH,CAAC,CAAC"}
@@ -1,4 +1,15 @@
1
1
  import { Request, Response, NextFunction } from 'express';
2
+ /**
3
+ * Express middleware stub for simulating SSO login.
4
+ *
5
+ * If an `email` query parameter is present, redirects to the SSO login callback with the email.
6
+ * Otherwise, logs an error and passes it to the next middleware.
7
+ *
8
+ * @param req - Express request object
9
+ * @param res - Express response object
10
+ * @param next - Express next middleware function
11
+ * @returns A redirect response or calls `next` with an error if no email is provided.
12
+ */
2
13
  declare const _default: (req: Request, res: Response, next: NextFunction) => Promise<void>;
3
14
  export default _default;
4
15
  //# sourceMappingURL=sso-login.stub.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sso-login.stub.d.ts","sourceRoot":"","sources":["../../../src/stubs/sso/sso-login.stub.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;yBAKpC,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY;AAArE,wBAUE"}
1
+ {"version":3,"file":"sso-login.stub.d.ts","sourceRoot":"","sources":["../../../src/stubs/sso/sso-login.stub.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAK1D;;;;;;;;;;GAUG;yBACmB,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY;AAArE,wBAUE"}
@@ -1,14 +1,23 @@
1
1
  import { Logger } from '@hmcts/nodejs-logging';
2
2
  const logger = Logger.getLogger('login-stub');
3
+ /**
4
+ * Express middleware stub for simulating SSO login.
5
+ *
6
+ * If an `email` query parameter is present, redirects to the SSO login callback with the email.
7
+ * Otherwise, logs an error and passes it to the next middleware.
8
+ *
9
+ * @param req - Express request object
10
+ * @param res - Express response object
11
+ * @param next - Express next middleware function
12
+ * @returns A redirect response or calls `next` with an error if no email is provided.
13
+ */
3
14
  export default async (req, res, next) => {
4
- const email = req.query['email'];
5
- if (email !== 'null') {
6
- res.redirect(`/sso/login-callback?email=${email}`);
7
- }
8
- else {
9
- const error = new Error('No email provided.');
10
- logger.error('Error on login-stub', error);
11
- return next(error);
15
+ const email = req.query['email']?.trim();
16
+ if (email) {
17
+ return res.redirect(`/sso/login-callback?email=${encodeURIComponent(email)}`);
12
18
  }
19
+ const error = new Error('No email provided.');
20
+ logger.error('Error on login-stub', error);
21
+ return next(error);
13
22
  };
14
23
  //# sourceMappingURL=sso-login.stub.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"sso-login.stub.js","sourceRoot":"","sources":["../../../src/stubs/sso/sso-login.stub.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE/C,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;AAE9C,eAAe,KAAK,EAAE,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;IACvE,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,CAAW,CAAC;IAE3C,IAAI,KAAK,KAAK,MAAM,EAAE,CAAC;QACrB,GAAG,CAAC,QAAQ,CAAC,6BAA6B,KAAK,EAAE,CAAC,CAAC;IACrD,CAAC;SAAM,CAAC;QACN,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;QAC9C,MAAM,CAAC,KAAK,CAAC,qBAAqB,EAAE,KAAK,CAAC,CAAC;QAC3C,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;AACH,CAAC,CAAC"}
1
+ {"version":3,"file":"sso-login.stub.js","sourceRoot":"","sources":["../../../src/stubs/sso/sso-login.stub.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE/C,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;AAE9C;;;;;;;;;;GAUG;AACH,eAAe,KAAK,EAAE,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;IACvE,MAAM,KAAK,GAAI,GAAG,CAAC,KAAK,CAAC,OAAO,CAAwB,EAAE,IAAI,EAAE,CAAC;IAEjE,IAAI,KAAK,EAAE,CAAC;QACV,OAAO,GAAG,CAAC,QAAQ,CAAC,6BAA6B,kBAAkB,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAChF,CAAC;IAED,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;IAC9C,MAAM,CAAC,KAAK,CAAC,qBAAqB,EAAE,KAAK,CAAC,CAAC;IAC3C,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC;AACrB,CAAC,CAAC"}
@@ -1,4 +1,16 @@
1
1
  import { NextFunction, Request, Response } from 'express';
2
+ /**
3
+ * Handles the SSO logout callback by destroying the user's session,
4
+ * clearing the authentication cookie, and redirecting to the home page.
5
+ *
6
+ * @param req - The Express request object.
7
+ * @param res - The Express response object.
8
+ * @param next - The next middleware function in the Express stack.
9
+ * @param prefix - The prefix used for the authentication cookie to be cleared.
10
+ *
11
+ * @remarks
12
+ * If an error occurs while destroying the session, it is logged and passed to the next middleware.
13
+ */
2
14
  declare const _default: (req: Request, res: Response, next: NextFunction, prefix: string) => void;
3
15
  export default _default;
4
16
  //# sourceMappingURL=sso-logout-callback.stub.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sso-logout-callback.stub.d.ts","sourceRoot":"","sources":["../../../src/stubs/sso/sso-logout-callback.stub.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;yBAG1C,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,EAAE,QAAQ,MAAM;AAA/E,wBAYE"}
1
+ {"version":3,"file":"sso-logout-callback.stub.d.ts","sourceRoot":"","sources":["../../../src/stubs/sso/sso-logout-callback.stub.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAG1D;;;;;;;;;;;GAWG;yBACa,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,EAAE,QAAQ,MAAM;AAA/E,wBAYE"}
@@ -1,4 +1,16 @@
1
1
  import { Logger } from '@hmcts/nodejs-logging';
2
+ /**
3
+ * Handles the SSO logout callback by destroying the user's session,
4
+ * clearing the authentication cookie, and redirecting to the home page.
5
+ *
6
+ * @param req - The Express request object.
7
+ * @param res - The Express response object.
8
+ * @param next - The next middleware function in the Express stack.
9
+ * @param prefix - The prefix used for the authentication cookie to be cleared.
10
+ *
11
+ * @remarks
12
+ * If an error occurs while destroying the session, it is logged and passed to the next middleware.
13
+ */
2
14
  export default (req, res, next, prefix) => {
3
15
  const logger = Logger.getLogger('logout-callback-stub');
4
16
  req.session.destroy((err) => {
@@ -1 +1 @@
1
- {"version":3,"file":"sso-logout-callback.stub.js","sourceRoot":"","sources":["../../../src/stubs/sso/sso-logout-callback.stub.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE/C,eAAe,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,MAAc,EAAE,EAAE;IACjF,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,sBAAsB,CAAC,CAAC;IAExD,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QAC1B,IAAI,GAAG,EAAE,CAAC;YACR,MAAM,CAAC,KAAK,CAAC,6BAA6B,GAAG,EAAE,CAAC,CAAC;YACjD,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC;QAED,GAAG,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QACxB,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;IACpB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}
1
+ {"version":3,"file":"sso-logout-callback.stub.js","sourceRoot":"","sources":["../../../src/stubs/sso/sso-logout-callback.stub.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE/C;;;;;;;;;;;GAWG;AACH,eAAe,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,MAAc,EAAE,EAAE;IACjF,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,sBAAsB,CAAC,CAAC;IAExD,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QAC1B,IAAI,GAAG,EAAE,CAAC;YACR,MAAM,CAAC,KAAK,CAAC,6BAA6B,GAAG,EAAE,CAAC,CAAC;YACjD,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC;QAED,GAAG,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QACxB,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;IACpB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}
@@ -1,4 +1,16 @@
1
- import { Request, Response, NextFunction } from 'express';
2
- declare const _default: (req: Request, res: Response, next: NextFunction) => Promise<void>;
1
+ import { Request, Response } from 'express';
2
+ /**
3
+ * Handles the SSO logout stub endpoint.
4
+ *
5
+ * - Prevents caching of the endpoint by setting appropriate headers.
6
+ * - Checks for the presence and validity of the access token in the session.
7
+ * - Responds with HTTP 401 and `false` if the access token is missing or expired.
8
+ * - Responds with HTTP 200 and `true` if the access token is present and valid.
9
+ *
10
+ * @param req - The Express request object.
11
+ * @param res - The Express response object.
12
+ * @returns Sends a boolean response indicating the validity of the access token.
13
+ */
14
+ declare const _default: (req: Request, res: Response) => Response<any, Record<string, any>>;
3
15
  export default _default;
4
16
  //# sourceMappingURL=sso-logout.stub.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sso-logout.stub.d.ts","sourceRoot":"","sources":["../../../src/stubs/sso/sso-logout.stub.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;yBAGpC,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY;AAArE,wBAEE"}
1
+ {"version":3,"file":"sso-logout.stub.d.ts","sourceRoot":"","sources":["../../../src/stubs/sso/sso-logout.stub.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAG5C;;;;;;;;;;;GAWG;yBACa,KAAK,OAAO,EAAE,KAAK,QAAQ;AAA3C,wBAWE"}
@@ -1,5 +1,23 @@
1
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
2
- export default async (req, res, next) => {
3
- res.redirect('/sso/logout-callback');
1
+ import { Jwt } from '../../utils';
2
+ /**
3
+ * Handles the SSO logout stub endpoint.
4
+ *
5
+ * - Prevents caching of the endpoint by setting appropriate headers.
6
+ * - Checks for the presence and validity of the access token in the session.
7
+ * - Responds with HTTP 401 and `false` if the access token is missing or expired.
8
+ * - Responds with HTTP 200 and `true` if the access token is present and valid.
9
+ *
10
+ * @param req - The Express request object.
11
+ * @param res - The Express response object.
12
+ * @returns Sends a boolean response indicating the validity of the access token.
13
+ */
14
+ export default (req, res) => {
15
+ // Don't allow caching of this endpoint
16
+ res.header('Cache-Control', 'no-store, must-revalidate');
17
+ const accessToken = req.session.securityToken?.access_token;
18
+ if (!accessToken || Jwt.isJwtExpired(accessToken)) {
19
+ return res.status(401).send(false);
20
+ }
21
+ return res.status(200).send(true);
4
22
  };
5
23
  //# sourceMappingURL=sso-logout.stub.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"sso-logout.stub.js","sourceRoot":"","sources":["../../../src/stubs/sso/sso-logout.stub.ts"],"names":[],"mappings":"AAEA,6DAA6D;AAC7D,eAAe,KAAK,EAAE,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;IACvE,GAAG,CAAC,QAAQ,CAAC,sBAAsB,CAAC,CAAC;AACvC,CAAC,CAAC"}
1
+ {"version":3,"file":"sso-logout.stub.js","sourceRoot":"","sources":["../../../src/stubs/sso/sso-logout.stub.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAElC;;;;;;;;;;;GAWG;AACH,eAAe,CAAC,GAAY,EAAE,GAAa,EAAE,EAAE;IAC7C,uCAAuC;IACvC,GAAG,CAAC,MAAM,CAAC,eAAe,EAAE,2BAA2B,CAAC,CAAC;IAEzD,MAAM,WAAW,GAAG,GAAG,CAAC,OAAO,CAAC,aAAa,EAAE,YAAY,CAAC;IAE5D,IAAI,CAAC,WAAW,IAAI,GAAG,CAAC,YAAY,CAAC,WAAW,CAAC,EAAE,CAAC;QAClD,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACrC,CAAC;IAED,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACpC,CAAC,CAAC"}
@@ -1,16 +0,0 @@
1
- declare class UserState {
2
- user_id: string;
3
- user_name: string;
4
- business_unit_user?: BusinessUnitUser[];
5
- }
6
- declare class BusinessUnitUser {
7
- business_user_id: string;
8
- business_unit: string;
9
- permissions?: Permissions[];
10
- }
11
- declare class Permissions {
12
- permission_id: number;
13
- permission_name: string;
14
- }
15
- export default UserState;
16
- //# sourceMappingURL=userState.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"userState.d.ts","sourceRoot":"","sources":["../../src/interfaces/userState.ts"],"names":[],"mappings":"AAAA,cAAM,SAAS;IACb,OAAO,EAAG,MAAM,CAAC;IACjB,SAAS,EAAG,MAAM,CAAC;IACnB,kBAAkB,CAAC,EAAE,gBAAgB,EAAE,CAAC;CACzC;AAED,cAAM,gBAAgB;IACpB,gBAAgB,EAAG,MAAM,CAAC;IAC1B,aAAa,EAAG,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,WAAW,EAAE,CAAC;CAC7B;AAED,cAAM,WAAW;IACf,aAAa,EAAG,MAAM,CAAC;IACvB,eAAe,EAAG,MAAM,CAAC;CAC1B;AAED,eAAe,SAAS,CAAC"}
@@ -1,16 +0,0 @@
1
- class UserState {
2
- user_id;
3
- user_name;
4
- business_unit_user;
5
- }
6
- class BusinessUnitUser {
7
- business_user_id;
8
- business_unit;
9
- permissions;
10
- }
11
- class Permissions {
12
- permission_id;
13
- permission_name;
14
- }
15
- export default UserState;
16
- //# sourceMappingURL=userState.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"userState.js","sourceRoot":"","sources":["../../src/interfaces/userState.ts"],"names":[],"mappings":"AAAA,MAAM,SAAS;IACb,OAAO,CAAU;IACjB,SAAS,CAAU;IACnB,kBAAkB,CAAsB;CACzC;AAED,MAAM,gBAAgB;IACpB,gBAAgB,CAAU;IAC1B,aAAa,CAAU;IACvB,WAAW,CAAiB;CAC7B;AAED,MAAM,WAAW;IACf,aAAa,CAAU;IACvB,eAAe,CAAU;CAC1B;AAED,eAAe,SAAS,CAAC"}
@@ -1,4 +0,0 @@
1
- import { Request, Response } from 'express';
2
- declare const sessionUserState: (req: Request, res: Response) => void;
3
- export default sessionUserState;
4
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/session/session-user-state/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAI5C,QAAA,MAAM,gBAAgB,GAAI,KAAK,OAAO,EAAE,KAAK,QAAQ,SAiBpD,CAAC;AAEF,eAAe,gBAAgB,CAAC"}