@atom8n/n8n 2.4.7 → 2.5.1

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 (231) hide show
  1. package/dist/build.tsbuildinfo +1 -1
  2. package/dist/chat/chat-service.types.d.ts +6 -6
  3. package/dist/commands/execute-batch.d.ts +2 -2
  4. package/dist/commands/execute.js +0 -0
  5. package/dist/commands/import/credentials.d.ts +2 -2
  6. package/dist/commands/import/credentials.js +0 -0
  7. package/dist/commands/import/workflow.d.ts +2 -2
  8. package/dist/commands/ldap/reset.d.ts +2 -2
  9. package/dist/commands/mcp.d.ts +23 -0
  10. package/dist/commands/mcp.js +315 -0
  11. package/dist/commands/run.d.ts +23 -0
  12. package/dist/commands/run.js +162 -0
  13. package/dist/controllers/annotation-tags.controller.ee.d.ts +1 -1
  14. package/dist/controllers/cli.controller.d.ts +26 -0
  15. package/dist/controllers/cli.controller.js +334 -0
  16. package/dist/controllers/orchestration.controller.js +0 -0
  17. package/dist/controllers/users.controller.d.ts +1 -1
  18. package/dist/environments.ee/source-control/source-control-status.service.ee.d.ts +2 -2
  19. package/dist/environments.ee/source-control/source-control.controller.ee.d.ts +4 -4
  20. package/dist/environments.ee/source-control/source-control.service.ee.d.ts +2 -2
  21. package/dist/environments.ee/source-control/types/source-control-set-branch.js +0 -0
  22. package/dist/eventbus/event-message-classes/index.js +0 -0
  23. package/dist/events/relays/workflow-failure-notification.event-relay.d.ts +13 -0
  24. package/dist/events/relays/workflow-failure-notification.event-relay.js +77 -0
  25. package/dist/executions/execution-data/types.d.ts +17 -0
  26. package/dist/executions/execution-data/types.js +2 -0
  27. package/dist/executions/failed-run-factory.d.ts +4 -0
  28. package/dist/executions/failed-run-factory.js +71 -0
  29. package/dist/index.d.ts +2 -1
  30. package/dist/index.js +8 -0
  31. package/dist/interfaces.d.ts +1 -1
  32. package/dist/license.js +1 -1
  33. package/dist/middlewares/webview-frame-options.d.ts +2 -0
  34. package/dist/middlewares/webview-frame-options.js +22 -0
  35. package/dist/modules/chat-hub/chat-hub-extractor.d.ts +22 -0
  36. package/dist/modules/chat-hub/chat-hub-extractor.js +63 -0
  37. package/dist/modules/dynamic-credentials.ee/credential-resolvers/storage/dynamic-credential-user-entry-storage.d.ts +11 -0
  38. package/dist/modules/dynamic-credentials.ee/credential-resolvers/storage/dynamic-credential-user-entry-storage.js +58 -0
  39. package/dist/modules/dynamic-credentials.ee/database/entities/dynamic-credential-user-entry.d.ts +12 -0
  40. package/dist/modules/dynamic-credentials.ee/database/entities/dynamic-credential-user-entry.js +64 -0
  41. package/dist/modules/dynamic-credentials.ee/database/repositories/dynamic-credential-user-entry.repository.d.ts +5 -0
  42. package/dist/modules/dynamic-credentials.ee/database/repositories/dynamic-credential-user-entry.repository.js +25 -0
  43. package/dist/modules/dynamic-credentials.ee/dynamic-credentials.config.d.ts +5 -0
  44. package/dist/modules/dynamic-credentials.ee/dynamic-credentials.config.js +36 -0
  45. package/dist/modules/dynamic-credentials.ee/services/dynamic-credential-cors.service.d.ts +12 -0
  46. package/dist/modules/dynamic-credentials.ee/services/dynamic-credential-cors.service.js +69 -0
  47. package/dist/modules/dynamic-credentials.ee/services/resolver-config-expression.service.d.ts +7 -0
  48. package/dist/modules/dynamic-credentials.ee/services/resolver-config-expression.service.js +46 -0
  49. package/dist/modules/insights/database/entities/insights-metadata.js +1 -1
  50. package/dist/modules/insights/database/repositories/insights-by-period-query.helper.js +4 -1
  51. package/dist/modules/insights/database/repositories/insights-by-period.repository.d.ts +1 -1
  52. package/dist/modules/insights/insights.module.d.ts +1 -1
  53. package/dist/modules/insights/insights.service.d.ts +1 -1
  54. package/dist/modules/log-streaming.ee/database/entities/event-destination.entity.d.ts +6 -0
  55. package/dist/modules/log-streaming.ee/database/entities/event-destination.entity.js +28 -0
  56. package/dist/modules/log-streaming.ee/database/entities/index.d.ts +1 -0
  57. package/dist/modules/log-streaming.ee/database/entities/index.js +5 -0
  58. package/dist/modules/log-streaming.ee/database/repositories/event-destination.repository.d.ts +5 -0
  59. package/dist/modules/log-streaming.ee/database/repositories/event-destination.repository.js +25 -0
  60. package/dist/modules/log-streaming.ee/destinations/message-event-bus-destination-from-db.d.ts +4 -0
  61. package/dist/modules/log-streaming.ee/destinations/message-event-bus-destination-from-db.js +24 -0
  62. package/dist/modules/log-streaming.ee/destinations/message-event-bus-destination-sentry.ee.d.ts +17 -0
  63. package/dist/modules/log-streaming.ee/destinations/message-event-bus-destination-sentry.ee.js +131 -0
  64. package/dist/modules/log-streaming.ee/destinations/message-event-bus-destination-syslog.ee.d.ts +22 -0
  65. package/dist/modules/log-streaming.ee/destinations/message-event-bus-destination-syslog.ee.js +116 -0
  66. package/dist/modules/log-streaming.ee/destinations/message-event-bus-destination-webhook.ee.d.ts +35 -0
  67. package/dist/modules/log-streaming.ee/destinations/message-event-bus-destination-webhook.ee.js +328 -0
  68. package/dist/modules/log-streaming.ee/destinations/message-event-bus-destination.ee.d.ts +28 -0
  69. package/dist/modules/log-streaming.ee/destinations/message-event-bus-destination.ee.js +74 -0
  70. package/dist/modules/log-streaming.ee/log-streaming-destination.service.d.ts +32 -0
  71. package/dist/modules/log-streaming.ee/log-streaming-destination.service.js +175 -0
  72. package/dist/modules/log-streaming.ee/log-streaming.controller.d.ts +15 -0
  73. package/dist/modules/log-streaming.ee/log-streaming.controller.js +149 -0
  74. package/dist/modules/log-streaming.ee/log-streaming.module.d.ts +5 -0
  75. package/dist/modules/log-streaming.ee/log-streaming.module.js +66 -0
  76. package/dist/modules/mcp/mcp-oauth.helpers.js +0 -0
  77. package/dist/modules/mcp/mcp.oauth-clients.controller.js +0 -0
  78. package/dist/modules/mcp/tools/execute-workflow.tool.d.ts +10 -10
  79. package/dist/modules/mcp/tools/schemas.d.ts +10 -10
  80. package/dist/modules/source-control.ee/constants.d.ts +17 -0
  81. package/dist/modules/source-control.ee/constants.js +22 -0
  82. package/dist/modules/source-control.ee/middleware/source-control-enabled-middleware.ee.d.ts +2 -0
  83. package/dist/modules/source-control.ee/middleware/source-control-enabled-middleware.ee.js +18 -0
  84. package/dist/modules/source-control.ee/source-control-export.service.ee.d.ts +37 -0
  85. package/dist/modules/source-control.ee/source-control-export.service.ee.js +426 -0
  86. package/dist/modules/source-control.ee/source-control-git.service.ee.d.ts +59 -0
  87. package/dist/modules/source-control.ee/source-control-git.service.ee.js +427 -0
  88. package/dist/modules/source-control.ee/source-control-helper.ee.d.ts +49 -0
  89. package/dist/modules/source-control.ee/source-control-helper.ee.js +241 -0
  90. package/dist/modules/source-control.ee/source-control-import.service.ee.d.ts +110 -0
  91. package/dist/modules/source-control.ee/source-control-import.service.ee.js +957 -0
  92. package/dist/modules/source-control.ee/source-control-preferences.service.ee.d.ts +46 -0
  93. package/dist/modules/source-control.ee/source-control-preferences.service.ee.js +309 -0
  94. package/dist/modules/source-control.ee/source-control-resource-helper.d.ts +4 -0
  95. package/dist/modules/source-control.ee/source-control-resource-helper.js +20 -0
  96. package/dist/modules/source-control.ee/source-control-scoped.service.d.ts +17 -0
  97. package/dist/modules/source-control.ee/source-control-scoped.service.js +134 -0
  98. package/dist/modules/source-control.ee/source-control-status.service.ee.d.ts +90 -0
  99. package/dist/modules/source-control.ee/source-control-status.service.ee.js +596 -0
  100. package/dist/modules/source-control.ee/source-control.config.d.ts +3 -0
  101. package/dist/modules/source-control.ee/source-control.config.js +26 -0
  102. package/dist/modules/source-control.ee/source-control.controller.ee.d.ts +157 -0
  103. package/dist/modules/source-control.ee/source-control.controller.ee.js +347 -0
  104. package/dist/modules/source-control.ee/source-control.module.d.ts +4 -0
  105. package/dist/modules/source-control.ee/source-control.module.js +59 -0
  106. package/dist/modules/source-control.ee/source-control.service.ee.d.ts +125 -0
  107. package/dist/modules/source-control.ee/source-control.service.ee.js +466 -0
  108. package/dist/modules/source-control.ee/types/export-result.d.ts +10 -0
  109. package/dist/modules/source-control.ee/types/export-result.js +2 -0
  110. package/dist/modules/source-control.ee/types/exportable-credential.d.ts +14 -0
  111. package/dist/modules/source-control.ee/types/exportable-credential.js +2 -0
  112. package/dist/modules/source-control.ee/types/exportable-folders.d.ts +11 -0
  113. package/dist/modules/source-control.ee/types/exportable-folders.js +2 -0
  114. package/dist/modules/source-control.ee/types/exportable-project.d.ts +17 -0
  115. package/dist/modules/source-control.ee/types/exportable-project.js +2 -0
  116. package/dist/modules/source-control.ee/types/exportable-tags.d.ts +5 -0
  117. package/dist/modules/source-control.ee/types/exportable-tags.js +2 -0
  118. package/dist/modules/source-control.ee/types/exportable-variable.d.ts +7 -0
  119. package/dist/modules/source-control.ee/types/exportable-variable.js +2 -0
  120. package/dist/modules/source-control.ee/types/exportable-workflow.d.ts +14 -0
  121. package/dist/modules/source-control.ee/types/exportable-workflow.js +2 -0
  122. package/dist/modules/source-control.ee/types/import-result.d.ts +20 -0
  123. package/dist/modules/source-control.ee/types/import-result.js +2 -0
  124. package/dist/modules/source-control.ee/types/key-pair-type.d.ts +1 -0
  125. package/dist/modules/source-control.ee/types/key-pair-type.js +2 -0
  126. package/dist/modules/source-control.ee/types/key-pair.d.ts +4 -0
  127. package/dist/modules/source-control.ee/types/key-pair.js +2 -0
  128. package/dist/modules/source-control.ee/types/requests.d.ts +21 -0
  129. package/dist/modules/source-control.ee/types/requests.js +2 -0
  130. package/dist/modules/source-control.ee/types/resource-owner.d.ts +17 -0
  131. package/dist/modules/source-control.ee/types/resource-owner.js +2 -0
  132. package/dist/modules/source-control.ee/types/source-control-commit.d.ts +3 -0
  133. package/dist/modules/source-control.ee/types/source-control-commit.js +20 -0
  134. package/dist/modules/source-control.ee/types/source-control-context.d.ts +7 -0
  135. package/dist/modules/source-control.ee/types/source-control-context.js +16 -0
  136. package/dist/modules/source-control.ee/types/source-control-disconnect.d.ts +3 -0
  137. package/dist/modules/source-control.ee/types/source-control-disconnect.js +21 -0
  138. package/dist/modules/source-control.ee/types/source-control-generate-key-pair.d.ts +4 -0
  139. package/dist/modules/source-control.ee/types/source-control-generate-key-pair.js +21 -0
  140. package/dist/modules/source-control.ee/types/source-control-get-status.d.ts +10 -0
  141. package/dist/modules/source-control.ee/types/source-control-get-status.js +42 -0
  142. package/dist/modules/source-control.ee/types/source-control-preferences.d.ts +17 -0
  143. package/dist/modules/source-control.ee/types/source-control-preferences.js +88 -0
  144. package/dist/modules/source-control.ee/types/source-control-push.d.ts +3 -0
  145. package/dist/modules/source-control.ee/types/source-control-push.js +21 -0
  146. package/dist/modules/source-control.ee/types/source-control-set-branch.d.ts +3 -0
  147. package/dist/modules/source-control.ee/types/source-control-set-branch.js +20 -0
  148. package/dist/modules/source-control.ee/types/source-control-set-read-only.d.ts +3 -0
  149. package/dist/modules/source-control.ee/types/source-control-set-read-only.js +20 -0
  150. package/dist/modules/source-control.ee/types/source-control-stage.d.ts +5 -0
  151. package/dist/modules/source-control.ee/types/source-control-stage.js +31 -0
  152. package/dist/modules/source-control.ee/types/source-control-workflow-version-id.d.ts +12 -0
  153. package/dist/modules/source-control.ee/types/source-control-workflow-version-id.js +2 -0
  154. package/dist/modules/sso-oidc/constants.d.ts +3 -0
  155. package/dist/modules/sso-oidc/constants.js +6 -0
  156. package/dist/modules/sso-oidc/oidc.controller.ee.d.ts +23 -0
  157. package/dist/modules/sso-oidc/oidc.controller.ee.js +123 -0
  158. package/dist/modules/sso-oidc/oidc.service.ee.d.ts +56 -0
  159. package/dist/modules/sso-oidc/oidc.service.ee.js +468 -0
  160. package/dist/modules/sso-oidc/sso-oidc.module.d.ts +4 -0
  161. package/dist/modules/sso-oidc/sso-oidc.module.js +55 -0
  162. package/dist/modules/sso-saml/constants.d.ts +3 -0
  163. package/dist/modules/sso-saml/constants.js +6 -0
  164. package/dist/modules/sso-saml/errors/invalid-saml-metadata-url.error.d.ts +4 -0
  165. package/dist/modules/sso-saml/errors/invalid-saml-metadata-url.error.js +10 -0
  166. package/dist/modules/sso-saml/errors/invalid-saml-metadata.error.d.ts +4 -0
  167. package/dist/modules/sso-saml/errors/invalid-saml-metadata.error.js +10 -0
  168. package/dist/modules/sso-saml/middleware/saml-enabled-middleware.d.ts +3 -0
  169. package/dist/modules/sso-saml/middleware/saml-enabled-middleware.js +22 -0
  170. package/dist/modules/sso-saml/saml-helpers.d.ts +19 -0
  171. package/dist/modules/sso-saml/saml-helpers.js +129 -0
  172. package/dist/modules/sso-saml/saml-validator.d.ts +16 -0
  173. package/dist/modules/sso-saml/saml-validator.js +129 -0
  174. package/dist/modules/sso-saml/saml.controller.ee.d.ts +50 -0
  175. package/dist/modules/sso-saml/saml.controller.ee.js +227 -0
  176. package/dist/modules/sso-saml/saml.service.ee.d.ts +52 -0
  177. package/dist/modules/sso-saml/saml.service.ee.js +462 -0
  178. package/dist/modules/sso-saml/schema/metadata-exchange.xsd.d.ts +2 -0
  179. package/dist/modules/sso-saml/schema/metadata-exchange.xsd.js +118 -0
  180. package/dist/modules/sso-saml/schema/oasis-200401-wss-wssecurity-secext-1.0.xsd.d.ts +2 -0
  181. package/dist/modules/sso-saml/schema/oasis-200401-wss-wssecurity-secext-1.0.xsd.js +201 -0
  182. package/dist/modules/sso-saml/schema/oasis-200401-wss-wssecurity-utility-1.0.xsd.d.ts +2 -0
  183. package/dist/modules/sso-saml/schema/oasis-200401-wss-wssecurity-utility-1.0.xsd.js +114 -0
  184. package/dist/modules/sso-saml/schema/saml-schema-assertion-2.0.xsd.d.ts +2 -0
  185. package/dist/modules/sso-saml/schema/saml-schema-assertion-2.0.xsd.js +289 -0
  186. package/dist/modules/sso-saml/schema/saml-schema-metadata-2.0.xsd.d.ts +2 -0
  187. package/dist/modules/sso-saml/schema/saml-schema-metadata-2.0.xsd.js +344 -0
  188. package/dist/modules/sso-saml/schema/saml-schema-protocol-2.0.xsd.d.ts +2 -0
  189. package/dist/modules/sso-saml/schema/saml-schema-protocol-2.0.xsd.js +308 -0
  190. package/dist/modules/sso-saml/schema/ws-addr.xsd.d.ts +2 -0
  191. package/dist/modules/sso-saml/schema/ws-addr.xsd.js +143 -0
  192. package/dist/modules/sso-saml/schema/ws-authorization.xsd.d.ts +2 -0
  193. package/dist/modules/sso-saml/schema/ws-authorization.xsd.js +151 -0
  194. package/dist/modules/sso-saml/schema/ws-federation.xsd.d.ts +2 -0
  195. package/dist/modules/sso-saml/schema/ws-federation.xsd.js +476 -0
  196. package/dist/modules/sso-saml/schema/ws-securitypolicy-1.2.xsd.d.ts +2 -0
  197. package/dist/modules/sso-saml/schema/ws-securitypolicy-1.2.xsd.js +1211 -0
  198. package/dist/modules/sso-saml/schema/xenc-schema.xsd.d.ts +2 -0
  199. package/dist/modules/sso-saml/schema/xenc-schema.xsd.js +151 -0
  200. package/dist/modules/sso-saml/schema/xml.xsd.d.ts +2 -0
  201. package/dist/modules/sso-saml/schema/xml.xsd.js +123 -0
  202. package/dist/modules/sso-saml/schema/xmldsig-core-schema.xsd.d.ts +2 -0
  203. package/dist/modules/sso-saml/schema/xmldsig-core-schema.xsd.js +324 -0
  204. package/dist/modules/sso-saml/service-provider.ee.d.ts +6 -0
  205. package/dist/modules/sso-saml/service-provider.ee.js +44 -0
  206. package/dist/modules/sso-saml/sso-saml.module.d.ts +4 -0
  207. package/dist/modules/sso-saml/sso-saml.module.js +55 -0
  208. package/dist/modules/sso-saml/types.d.ts +4 -0
  209. package/dist/modules/sso-saml/types.js +2 -0
  210. package/dist/modules/sso-saml/views/init-sso-post.d.ts +2 -0
  211. package/dist/modules/sso-saml/views/init-sso-post.js +16 -0
  212. package/dist/node-lib.d.ts +10 -0
  213. package/dist/node-lib.js +137 -0
  214. package/dist/push/index.d.ts +1 -1
  215. package/dist/server.d.ts +1 -0
  216. package/dist/server.js +1 -0
  217. package/dist/services/cors-service.d.ts +7 -0
  218. package/dist/services/cors-service.js +50 -0
  219. package/dist/services/static-auth-service.d.ts +4 -0
  220. package/dist/services/static-auth-service.js +29 -0
  221. package/dist/sso.ee/saml/schema/metadata-exchange.xsd.js +0 -0
  222. package/dist/task-runners/task-broker/errors/task-runner-accept-timeout.error.js +0 -0
  223. package/dist/typecheck.tsbuildinfo +1 -0
  224. package/dist/user-management/email/templates/workflow-failure.handlebars +211 -0
  225. package/dist/utils/cors.util.d.ts +2 -0
  226. package/dist/utils/cors.util.js +17 -0
  227. package/dist/webhooks/waiting-forms.js +3 -3
  228. package/dist/webhooks/waiting-webhooks.js +2 -0
  229. package/dist/workflows/workflow.service.d.ts +2 -2
  230. package/dist/workflows/workflows.controller.d.ts +6 -6
  231. package/package.json +22 -21
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.OidcController = void 0;
16
+ const api_types_1 = require("@n8n/api-types");
17
+ const backend_common_1 = require("@n8n/backend-common");
18
+ const config_1 = require("@n8n/config");
19
+ const constants_1 = require("@n8n/constants");
20
+ const decorators_1 = require("@n8n/decorators");
21
+ const auth_service_1 = require("../../auth/auth.service");
22
+ const constants_2 = require("../../constants");
23
+ const bad_request_error_1 = require("../../errors/response-errors/bad-request.error");
24
+ const url_service_1 = require("../../services/url.service");
25
+ const constants_3 = require("./constants");
26
+ const oidc_service_ee_1 = require("./oidc.service.ee");
27
+ let OidcController = class OidcController {
28
+ constructor(oidcService, authService, urlService, globalConfig, logger) {
29
+ this.oidcService = oidcService;
30
+ this.authService = authService;
31
+ this.urlService = urlService;
32
+ this.globalConfig = globalConfig;
33
+ this.logger = logger;
34
+ }
35
+ async retrieveConfiguration(_req) {
36
+ const config = await this.oidcService.loadConfig();
37
+ if (config.clientSecret) {
38
+ config.clientSecret = constants_3.OIDC_CLIENT_SECRET_REDACTED_VALUE;
39
+ }
40
+ return config;
41
+ }
42
+ async saveConfiguration(_req, _res, payload) {
43
+ await this.oidcService.updateConfig(payload);
44
+ const config = this.oidcService.getRedactedConfig();
45
+ return config;
46
+ }
47
+ async redirectToAuthProvider(_req, res) {
48
+ const authorization = await this.oidcService.generateLoginUrl();
49
+ const { samesite, secure } = this.globalConfig.auth.cookie;
50
+ res.cookie(constants_2.OIDC_STATE_COOKIE_NAME, authorization.state, {
51
+ maxAge: 15 * constants_1.Time.minutes.toMilliseconds,
52
+ httpOnly: true,
53
+ sameSite: samesite,
54
+ secure,
55
+ });
56
+ res.cookie(constants_2.OIDC_NONCE_COOKIE_NAME, authorization.nonce, {
57
+ maxAge: 15 * constants_1.Time.minutes.toMilliseconds,
58
+ httpOnly: true,
59
+ sameSite: samesite,
60
+ secure,
61
+ });
62
+ res.redirect(authorization.url.toString());
63
+ }
64
+ async callbackHandler(req, res) {
65
+ const fullUrl = `${this.urlService.getInstanceBaseUrl()}${req.originalUrl}`;
66
+ const callbackUrl = new URL(fullUrl);
67
+ const state = req.cookies[constants_2.OIDC_STATE_COOKIE_NAME];
68
+ if (typeof state !== 'string') {
69
+ this.logger.error('State is missing');
70
+ throw new bad_request_error_1.BadRequestError('Invalid state');
71
+ }
72
+ const nonce = req.cookies[constants_2.OIDC_NONCE_COOKIE_NAME];
73
+ if (typeof nonce !== 'string') {
74
+ this.logger.error('Nonce is missing');
75
+ throw new bad_request_error_1.BadRequestError('Invalid nonce');
76
+ }
77
+ const user = await this.oidcService.loginUser(callbackUrl, state, nonce);
78
+ res.clearCookie(constants_2.OIDC_STATE_COOKIE_NAME);
79
+ res.clearCookie(constants_2.OIDC_NONCE_COOKIE_NAME);
80
+ this.authService.issueCookie(res, user, true, req.browserId);
81
+ res.redirect('/');
82
+ }
83
+ };
84
+ exports.OidcController = OidcController;
85
+ __decorate([
86
+ (0, decorators_1.Get)('/config'),
87
+ (0, decorators_1.Licensed)('feat:oidc'),
88
+ (0, decorators_1.GlobalScope)('oidc:manage'),
89
+ __metadata("design:type", Function),
90
+ __metadata("design:paramtypes", [Object]),
91
+ __metadata("design:returntype", Promise)
92
+ ], OidcController.prototype, "retrieveConfiguration", null);
93
+ __decorate([
94
+ (0, decorators_1.Post)('/config'),
95
+ (0, decorators_1.Licensed)('feat:oidc'),
96
+ (0, decorators_1.GlobalScope)('oidc:manage'),
97
+ __param(2, decorators_1.Body),
98
+ __metadata("design:type", Function),
99
+ __metadata("design:paramtypes", [Object, Object, api_types_1.OidcConfigDto]),
100
+ __metadata("design:returntype", Promise)
101
+ ], OidcController.prototype, "saveConfiguration", null);
102
+ __decorate([
103
+ (0, decorators_1.Get)('/login', { skipAuth: true }),
104
+ (0, decorators_1.Licensed)('feat:oidc'),
105
+ __metadata("design:type", Function),
106
+ __metadata("design:paramtypes", [Object, Object]),
107
+ __metadata("design:returntype", Promise)
108
+ ], OidcController.prototype, "redirectToAuthProvider", null);
109
+ __decorate([
110
+ (0, decorators_1.Get)('/callback', { skipAuth: true }),
111
+ (0, decorators_1.Licensed)('feat:oidc'),
112
+ __metadata("design:type", Function),
113
+ __metadata("design:paramtypes", [Object, Object]),
114
+ __metadata("design:returntype", Promise)
115
+ ], OidcController.prototype, "callbackHandler", null);
116
+ exports.OidcController = OidcController = __decorate([
117
+ (0, decorators_1.RestController)('/sso/oidc'),
118
+ __metadata("design:paramtypes", [oidc_service_ee_1.OidcService,
119
+ auth_service_1.AuthService,
120
+ url_service_1.UrlService,
121
+ config_1.GlobalConfig,
122
+ backend_common_1.Logger])
123
+ ], OidcController);
@@ -0,0 +1,56 @@
1
+ import { OidcConfigDto } from '@n8n/api-types';
2
+ import { Logger } from '@n8n/backend-common';
3
+ import { GlobalConfig } from '@n8n/config';
4
+ import { AuthIdentityRepository, SettingsRepository, type User, UserRepository } from '@n8n/db';
5
+ import { Cipher, InstanceSettings } from 'n8n-core';
6
+ import { ProvisioningService } from '../../modules/provisioning.ee/provisioning.service.ee';
7
+ import { JwtService } from '../../services/jwt.service';
8
+ import { UrlService } from '../../services/url.service';
9
+ type OidcRuntimeConfig = Pick<OidcConfigDto, 'clientId' | 'clientSecret' | 'loginEnabled' | 'prompt' | 'authenticationContextClassReference'> & {
10
+ discoveryEndpoint: URL;
11
+ };
12
+ export declare class OidcService {
13
+ private readonly settingsRepository;
14
+ private readonly authIdentityRepository;
15
+ private readonly urlService;
16
+ private readonly globalConfig;
17
+ private readonly userRepository;
18
+ private readonly cipher;
19
+ private readonly logger;
20
+ private readonly jwtService;
21
+ private readonly instanceSettings;
22
+ private readonly provisioningService;
23
+ private oidcConfig;
24
+ constructor(settingsRepository: SettingsRepository, authIdentityRepository: AuthIdentityRepository, urlService: UrlService, globalConfig: GlobalConfig, userRepository: UserRepository, cipher: Cipher, logger: Logger, jwtService: JwtService, instanceSettings: InstanceSettings, provisioningService: ProvisioningService);
25
+ init(): Promise<void>;
26
+ getCallbackUrl(): string;
27
+ getRedactedConfig(): OidcConfigDto;
28
+ generateState(): {
29
+ signed: string;
30
+ plaintext: string;
31
+ };
32
+ verifyState(signedState: string): string;
33
+ generateNonce(): {
34
+ signed: string;
35
+ plaintext: string;
36
+ };
37
+ verifyNonce(signedNonce: string): string;
38
+ generateLoginUrl(): Promise<{
39
+ url: URL;
40
+ state: string;
41
+ nonce: string;
42
+ }>;
43
+ loginUser(callbackUrl: URL, storedState: string, storedNonce: string): Promise<User>;
44
+ private applySsoProvisioning;
45
+ private broadcastReloadOIDCConfigurationCommand;
46
+ private isReloading;
47
+ reload(): Promise<void>;
48
+ loadConfigurationFromDatabase(decryptSecret?: boolean): Promise<OidcRuntimeConfig | undefined>;
49
+ loadConfig(decryptSecret?: boolean): Promise<OidcRuntimeConfig>;
50
+ updateConfig(newConfig: OidcConfigDto): Promise<void>;
51
+ private setOidcLoginEnabled;
52
+ private cachedOidcConfiguration;
53
+ private createProxyAwareConfiguration;
54
+ private getOidcConfiguration;
55
+ }
56
+ export {};
@@ -0,0 +1,468 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
23
+ };
24
+ var __importStar = (this && this.__importStar) || (function () {
25
+ var ownKeys = function(o) {
26
+ ownKeys = Object.getOwnPropertyNames || function (o) {
27
+ var ar = [];
28
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
29
+ return ar;
30
+ };
31
+ return ownKeys(o);
32
+ };
33
+ return function (mod) {
34
+ if (mod && mod.__esModule) return mod;
35
+ var result = {};
36
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
37
+ __setModuleDefault(result, mod);
38
+ return result;
39
+ };
40
+ })();
41
+ var __metadata = (this && this.__metadata) || function (k, v) {
42
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
43
+ };
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ exports.OidcService = void 0;
46
+ const api_types_1 = require("@n8n/api-types");
47
+ const backend_common_1 = require("@n8n/backend-common");
48
+ const config_1 = require("@n8n/config");
49
+ const db_1 = require("@n8n/db");
50
+ const decorators_1 = require("@n8n/decorators");
51
+ const di_1 = require("@n8n/di");
52
+ const crypto_1 = require("crypto");
53
+ const n8n_core_1 = require("n8n-core");
54
+ const n8n_workflow_1 = require("n8n-workflow");
55
+ const client = __importStar(require("openid-client"));
56
+ const undici_1 = require("undici");
57
+ const bad_request_error_1 = require("../../errors/response-errors/bad-request.error");
58
+ const forbidden_error_1 = require("../../errors/response-errors/forbidden.error");
59
+ const internal_server_error_1 = require("../../errors/response-errors/internal-server.error");
60
+ const provisioning_service_ee_1 = require("../../modules/provisioning.ee/provisioning.service.ee");
61
+ const jwt_service_1 = require("../../services/jwt.service");
62
+ const url_service_1 = require("../../services/url.service");
63
+ const sso_helpers_1 = require("../../sso.ee/sso-helpers");
64
+ const constants_1 = require("./constants");
65
+ const DEFAULT_OIDC_CONFIG = {
66
+ clientId: '',
67
+ clientSecret: '',
68
+ discoveryEndpoint: '',
69
+ loginEnabled: false,
70
+ prompt: 'select_account',
71
+ authenticationContextClassReference: [],
72
+ };
73
+ const DEFAULT_OIDC_RUNTIME_CONFIG = {
74
+ ...DEFAULT_OIDC_CONFIG,
75
+ discoveryEndpoint: new URL('http://n8n.io/not-set'),
76
+ };
77
+ let OidcService = class OidcService {
78
+ constructor(settingsRepository, authIdentityRepository, urlService, globalConfig, userRepository, cipher, logger, jwtService, instanceSettings, provisioningService) {
79
+ this.settingsRepository = settingsRepository;
80
+ this.authIdentityRepository = authIdentityRepository;
81
+ this.urlService = urlService;
82
+ this.globalConfig = globalConfig;
83
+ this.userRepository = userRepository;
84
+ this.cipher = cipher;
85
+ this.logger = logger;
86
+ this.jwtService = jwtService;
87
+ this.instanceSettings = instanceSettings;
88
+ this.provisioningService = provisioningService;
89
+ this.oidcConfig = DEFAULT_OIDC_RUNTIME_CONFIG;
90
+ this.isReloading = false;
91
+ }
92
+ async init() {
93
+ this.oidcConfig = await this.loadConfig(true);
94
+ this.logger.debug(`OIDC login is ${this.oidcConfig.loginEnabled ? 'enabled' : 'disabled'}.`);
95
+ await this.setOidcLoginEnabled(this.oidcConfig.loginEnabled);
96
+ }
97
+ getCallbackUrl() {
98
+ return `${this.urlService.getInstanceBaseUrl()}/${this.globalConfig.endpoints.rest}/sso/oidc/callback`;
99
+ }
100
+ getRedactedConfig() {
101
+ return {
102
+ ...this.oidcConfig,
103
+ discoveryEndpoint: this.oidcConfig.discoveryEndpoint.toString(),
104
+ clientSecret: constants_1.OIDC_CLIENT_SECRET_REDACTED_VALUE,
105
+ };
106
+ }
107
+ generateState() {
108
+ const state = `n8n_state:${(0, crypto_1.randomUUID)()}`;
109
+ return {
110
+ signed: this.jwtService.sign({ state }, { expiresIn: '15m' }),
111
+ plaintext: state,
112
+ };
113
+ }
114
+ verifyState(signedState) {
115
+ let state;
116
+ try {
117
+ const decodedState = this.jwtService.verify(signedState);
118
+ state = decodedState?.state;
119
+ }
120
+ catch (error) {
121
+ this.logger.error('Failed to verify state', { error });
122
+ throw new bad_request_error_1.BadRequestError('Invalid state');
123
+ }
124
+ if (typeof state !== 'string') {
125
+ this.logger.error('Provided state has an invalid format');
126
+ throw new bad_request_error_1.BadRequestError('Invalid state');
127
+ }
128
+ const splitState = state.split(':');
129
+ if (splitState.length !== 2 || splitState[0] !== 'n8n_state') {
130
+ this.logger.error('Provided state is missing the well-known prefix');
131
+ throw new bad_request_error_1.BadRequestError('Invalid state');
132
+ }
133
+ if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(splitState[1])) {
134
+ this.logger.error('Provided state is not formatted correctly');
135
+ throw new bad_request_error_1.BadRequestError('Invalid state');
136
+ }
137
+ return state;
138
+ }
139
+ generateNonce() {
140
+ const nonce = `n8n_nonce:${(0, crypto_1.randomUUID)()}`;
141
+ return {
142
+ signed: this.jwtService.sign({ nonce }, { expiresIn: '15m' }),
143
+ plaintext: nonce,
144
+ };
145
+ }
146
+ verifyNonce(signedNonce) {
147
+ let nonce;
148
+ try {
149
+ const decodedNonce = this.jwtService.verify(signedNonce);
150
+ nonce = decodedNonce?.nonce;
151
+ }
152
+ catch (error) {
153
+ this.logger.error('Failed to verify nonce', { error });
154
+ throw new bad_request_error_1.BadRequestError('Invalid nonce');
155
+ }
156
+ if (typeof nonce !== 'string') {
157
+ this.logger.error('Provided nonce has an invalid format');
158
+ throw new bad_request_error_1.BadRequestError('Invalid nonce');
159
+ }
160
+ const splitNonce = nonce.split(':');
161
+ if (splitNonce.length !== 2 || splitNonce[0] !== 'n8n_nonce') {
162
+ this.logger.error('Provided nonce is missing the well-known prefix');
163
+ throw new bad_request_error_1.BadRequestError('Invalid nonce');
164
+ }
165
+ if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(splitNonce[1])) {
166
+ this.logger.error('Provided nonce is not formatted correctly');
167
+ throw new bad_request_error_1.BadRequestError('Invalid nonce');
168
+ }
169
+ return nonce;
170
+ }
171
+ async generateLoginUrl() {
172
+ const configuration = await this.getOidcConfiguration();
173
+ const state = this.generateState();
174
+ const nonce = this.generateNonce();
175
+ const prompt = this.oidcConfig.prompt;
176
+ const authenticationContextClassReference = this.oidcConfig.authenticationContextClassReference;
177
+ const provisioningConfig = await this.provisioningService.getConfig();
178
+ const provisioningEnabled = provisioningConfig.scopesProvisionInstanceRole ||
179
+ provisioningConfig.scopesProvisionProjectRoles;
180
+ const scope = provisioningEnabled
181
+ ? `openid email profile ${provisioningConfig.scopesName}`
182
+ : 'openid email profile';
183
+ const authorizationURL = client.buildAuthorizationUrl(configuration, {
184
+ redirect_uri: this.getCallbackUrl(),
185
+ response_type: 'code',
186
+ scope,
187
+ prompt,
188
+ state: state.plaintext,
189
+ nonce: nonce.plaintext,
190
+ ...(authenticationContextClassReference.length > 0 && {
191
+ acr_values: authenticationContextClassReference.join(' '),
192
+ }),
193
+ });
194
+ return { url: authorizationURL, state: state.signed, nonce: nonce.signed };
195
+ }
196
+ async loginUser(callbackUrl, storedState, storedNonce) {
197
+ const configuration = await this.getOidcConfiguration();
198
+ const expectedState = this.verifyState(storedState);
199
+ const expectedNonce = this.verifyNonce(storedNonce);
200
+ let tokens;
201
+ try {
202
+ tokens = await client.authorizationCodeGrant(configuration, callbackUrl, {
203
+ expectedState,
204
+ expectedNonce,
205
+ });
206
+ }
207
+ catch (error) {
208
+ this.logger.error('Failed to exchange authorization code for tokens', { error });
209
+ throw new bad_request_error_1.BadRequestError('Invalid authorization code');
210
+ }
211
+ let claims;
212
+ try {
213
+ claims = tokens.claims();
214
+ }
215
+ catch (error) {
216
+ this.logger.error('Failed to extract claims from tokens', { error });
217
+ throw new bad_request_error_1.BadRequestError('Invalid token');
218
+ }
219
+ if (!claims) {
220
+ throw new forbidden_error_1.ForbiddenError('No claims found in the OIDC token');
221
+ }
222
+ let userInfo;
223
+ try {
224
+ userInfo = await client.fetchUserInfo(configuration, tokens.access_token, claims.sub);
225
+ }
226
+ catch (error) {
227
+ this.logger.error('Failed to fetch user info', { error });
228
+ throw new bad_request_error_1.BadRequestError('Invalid token');
229
+ }
230
+ if (!userInfo.email) {
231
+ throw new bad_request_error_1.BadRequestError('An email is required');
232
+ }
233
+ if (!(0, db_1.isValidEmail)(userInfo.email)) {
234
+ throw new bad_request_error_1.BadRequestError('Invalid email format');
235
+ }
236
+ const openidUser = await this.authIdentityRepository.findOne({
237
+ where: { providerId: claims.sub, providerType: 'oidc' },
238
+ relations: {
239
+ user: {
240
+ role: true,
241
+ },
242
+ },
243
+ });
244
+ if (openidUser) {
245
+ await this.applySsoProvisioning(openidUser.user, claims);
246
+ return openidUser.user;
247
+ }
248
+ const foundUser = await this.userRepository.findOne({
249
+ where: { email: userInfo.email },
250
+ relations: ['authIdentities', 'role'],
251
+ });
252
+ if (foundUser) {
253
+ this.logger.debug(`OIDC login: User with email ${userInfo.email} already exists, linking OIDC identity.`);
254
+ const id = this.authIdentityRepository.create({
255
+ providerId: claims.sub,
256
+ providerType: 'oidc',
257
+ userId: foundUser.id,
258
+ });
259
+ await this.authIdentityRepository.save(id);
260
+ await this.applySsoProvisioning(foundUser, claims);
261
+ return foundUser;
262
+ }
263
+ return await this.userRepository.manager.transaction(async (trx) => {
264
+ const { user } = await this.userRepository.createUserWithProject({
265
+ firstName: userInfo.given_name,
266
+ lastName: userInfo.family_name,
267
+ email: userInfo.email,
268
+ authIdentities: [],
269
+ role: db_1.GLOBAL_MEMBER_ROLE,
270
+ password: 'no password set',
271
+ }, trx);
272
+ await trx.save(trx.create(db_1.AuthIdentity, {
273
+ providerId: claims.sub,
274
+ providerType: 'oidc',
275
+ userId: user.id,
276
+ }));
277
+ await this.applySsoProvisioning(user, claims);
278
+ return user;
279
+ });
280
+ }
281
+ async applySsoProvisioning(user, claims) {
282
+ const provisioningConfig = await this.provisioningService.getConfig();
283
+ const projectRoleMapping = claims[provisioningConfig.scopesProjectsRolesClaimName];
284
+ const instanceRole = claims[provisioningConfig.scopesInstanceRoleClaimName];
285
+ if (instanceRole) {
286
+ await this.provisioningService.provisionInstanceRoleForUser(user, instanceRole);
287
+ }
288
+ if (projectRoleMapping) {
289
+ await this.provisioningService.provisionProjectRolesForUser(user.id, projectRoleMapping);
290
+ }
291
+ }
292
+ async broadcastReloadOIDCConfigurationCommand() {
293
+ if (this.instanceSettings.isMultiMain) {
294
+ const { Publisher } = await Promise.resolve().then(() => __importStar(require('../../scaling/pubsub/publisher.service')));
295
+ await di_1.Container.get(Publisher).publishCommand({ command: 'reload-oidc-config' });
296
+ }
297
+ }
298
+ async reload() {
299
+ if (this.isReloading) {
300
+ this.logger.warn('OIDC configuration reload already in progress');
301
+ return;
302
+ }
303
+ this.isReloading = true;
304
+ try {
305
+ this.logger.debug('OIDC configuration changed, starting to load it from the database');
306
+ const configFromDB = await this.loadConfigurationFromDatabase(true);
307
+ if (configFromDB) {
308
+ this.oidcConfig = configFromDB;
309
+ this.cachedOidcConfiguration = undefined;
310
+ }
311
+ else {
312
+ this.logger.warn('OIDC configuration not found in database, ignoring reload message');
313
+ }
314
+ await (0, sso_helpers_1.reloadAuthenticationMethod)();
315
+ const isOidcLoginEnabled = (0, sso_helpers_1.isOidcCurrentAuthenticationMethod)();
316
+ this.logger.debug(`OIDC login is now ${isOidcLoginEnabled ? 'enabled' : 'disabled'}.`);
317
+ di_1.Container.get(config_1.GlobalConfig).sso.oidc.loginEnabled = isOidcLoginEnabled;
318
+ }
319
+ catch (error) {
320
+ this.logger.error('OIDC configuration changed, failed to reload OIDC configuration', {
321
+ error,
322
+ });
323
+ }
324
+ finally {
325
+ this.isReloading = false;
326
+ }
327
+ }
328
+ async loadConfigurationFromDatabase(decryptSecret = false) {
329
+ const configFromDB = await this.settingsRepository.findByKey(constants_1.OIDC_PREFERENCES_DB_KEY);
330
+ if (configFromDB) {
331
+ try {
332
+ const configValue = (0, n8n_workflow_1.jsonParse)(configFromDB.value);
333
+ if (configValue.discoveryEndpoint === '')
334
+ return undefined;
335
+ const oidcConfig = api_types_1.OidcConfigDto.parse(configValue);
336
+ const discoveryUrl = new URL(oidcConfig.discoveryEndpoint);
337
+ if (oidcConfig.clientSecret && decryptSecret) {
338
+ oidcConfig.clientSecret = this.cipher.decrypt(oidcConfig.clientSecret);
339
+ }
340
+ return {
341
+ ...oidcConfig,
342
+ discoveryEndpoint: discoveryUrl,
343
+ };
344
+ }
345
+ catch (error) {
346
+ this.logger.warn('Failed to load OIDC configuration from database, falling back to default configuration.', { error });
347
+ }
348
+ }
349
+ return undefined;
350
+ }
351
+ async loadConfig(decryptSecret = false) {
352
+ const currentConfig = await this.loadConfigurationFromDatabase(decryptSecret);
353
+ if (currentConfig) {
354
+ return currentConfig;
355
+ }
356
+ return DEFAULT_OIDC_RUNTIME_CONFIG;
357
+ }
358
+ async updateConfig(newConfig) {
359
+ const isEnablingOidcWhileOtherSsoProtocolIsAlreadyEnabled = newConfig.loginEnabled &&
360
+ !(0, sso_helpers_1.isEmailCurrentAuthenticationMethod)() &&
361
+ !(0, sso_helpers_1.isOidcCurrentAuthenticationMethod)();
362
+ if (isEnablingOidcWhileOtherSsoProtocolIsAlreadyEnabled) {
363
+ throw new internal_server_error_1.InternalServerError(`Cannot switch OIDC login enabled state when an authentication method other than email or OIDC is active (current: ${(0, sso_helpers_1.getCurrentAuthenticationMethod)()})`);
364
+ }
365
+ let discoveryEndpoint;
366
+ try {
367
+ discoveryEndpoint = new URL(newConfig.discoveryEndpoint);
368
+ }
369
+ catch (error) {
370
+ this.logger.error(`The provided endpoint is not a valid URL: ${newConfig.discoveryEndpoint}`);
371
+ throw new n8n_workflow_1.UserError('Provided discovery endpoint is not a valid URL');
372
+ }
373
+ if (newConfig.clientSecret === constants_1.OIDC_CLIENT_SECRET_REDACTED_VALUE) {
374
+ newConfig.clientSecret = this.oidcConfig.clientSecret;
375
+ }
376
+ try {
377
+ const discoveredMetadata = await this.createProxyAwareConfiguration(discoveryEndpoint, newConfig.clientId, newConfig.clientSecret);
378
+ this.logger.debug(`Discovered OIDC metadata: ${JSON.stringify(discoveredMetadata)}`);
379
+ }
380
+ catch (error) {
381
+ this.logger.error('Failed to discover OIDC metadata', { error });
382
+ throw new n8n_workflow_1.UserError('Failed to discover OIDC metadata, based on the provided configuration');
383
+ }
384
+ await this.settingsRepository.save({
385
+ key: constants_1.OIDC_PREFERENCES_DB_KEY,
386
+ value: JSON.stringify({
387
+ ...newConfig,
388
+ clientSecret: this.cipher.encrypt(newConfig.clientSecret),
389
+ }),
390
+ loadOnStartup: true,
391
+ });
392
+ this.oidcConfig = {
393
+ ...newConfig,
394
+ discoveryEndpoint,
395
+ };
396
+ this.cachedOidcConfiguration = undefined;
397
+ this.logger.debug(`OIDC login is now ${this.oidcConfig.loginEnabled ? 'enabled' : 'disabled'}.`);
398
+ await this.setOidcLoginEnabled(this.oidcConfig.loginEnabled);
399
+ await this.broadcastReloadOIDCConfigurationCommand();
400
+ }
401
+ async setOidcLoginEnabled(enabled) {
402
+ const currentAuthenticationMethod = (0, sso_helpers_1.getCurrentAuthenticationMethod)();
403
+ const isEnablingOidcWhileOtherSsoProtocolIsAlreadyEnabled = enabled && !(0, sso_helpers_1.isEmailCurrentAuthenticationMethod)() && !(0, sso_helpers_1.isOidcCurrentAuthenticationMethod)();
404
+ if (isEnablingOidcWhileOtherSsoProtocolIsAlreadyEnabled) {
405
+ throw new internal_server_error_1.InternalServerError(`Cannot switch OIDC login enabled state when an authentication method other than email or OIDC is active (current: ${currentAuthenticationMethod})`);
406
+ }
407
+ const targetAuthenticationMethod = !enabled && currentAuthenticationMethod === 'oidc' ? 'email' : currentAuthenticationMethod;
408
+ di_1.Container.get(config_1.GlobalConfig).sso.oidc.loginEnabled = enabled;
409
+ await (0, sso_helpers_1.setCurrentAuthenticationMethod)(enabled ? 'oidc' : targetAuthenticationMethod);
410
+ }
411
+ async createProxyAwareConfiguration(discoveryUrl, clientId, clientSecret) {
412
+ const configuration = await client.discovery(discoveryUrl, clientId, clientSecret);
413
+ const hasProxyConfig = process.env.HTTP_PROXY ?? process.env.HTTPS_PROXY ?? process.env.ALL_PROXY;
414
+ if (hasProxyConfig) {
415
+ this.logger.debug('Configuring OIDC client with proxy support', {
416
+ HTTP_PROXY: process.env.HTTP_PROXY,
417
+ HTTPS_PROXY: process.env.HTTPS_PROXY,
418
+ NO_PROXY: process.env.NO_PROXY,
419
+ ALL_PROXY: process.env.ALL_PROXY,
420
+ });
421
+ const proxyAgent = new undici_1.EnvHttpProxyAgent();
422
+ configuration[client.customFetch] = async (...args) => {
423
+ const [url, options] = args;
424
+ return await fetch(url, {
425
+ ...options,
426
+ dispatcher: proxyAgent,
427
+ });
428
+ };
429
+ }
430
+ return configuration;
431
+ }
432
+ async getOidcConfiguration() {
433
+ const now = Date.now();
434
+ if (this.cachedOidcConfiguration === undefined ||
435
+ now >= this.cachedOidcConfiguration.validTill.getTime() ||
436
+ this.oidcConfig.discoveryEndpoint.toString() !==
437
+ this.cachedOidcConfiguration.discoveryEndpoint.toString() ||
438
+ this.oidcConfig.clientId !== this.cachedOidcConfiguration.clientId ||
439
+ this.oidcConfig.clientSecret !== this.cachedOidcConfiguration.clientSecret) {
440
+ this.cachedOidcConfiguration = {
441
+ ...this.oidcConfig,
442
+ configuration: this.createProxyAwareConfiguration(this.oidcConfig.discoveryEndpoint, this.oidcConfig.clientId, this.oidcConfig.clientSecret),
443
+ validTill: new Date(Date.now() + 60 * 60 * 1000),
444
+ };
445
+ }
446
+ return await this.cachedOidcConfiguration.configuration;
447
+ }
448
+ };
449
+ exports.OidcService = OidcService;
450
+ __decorate([
451
+ (0, decorators_1.OnPubSubEvent)('reload-oidc-config'),
452
+ __metadata("design:type", Function),
453
+ __metadata("design:paramtypes", []),
454
+ __metadata("design:returntype", Promise)
455
+ ], OidcService.prototype, "reload", null);
456
+ exports.OidcService = OidcService = __decorate([
457
+ (0, di_1.Service)(),
458
+ __metadata("design:paramtypes", [db_1.SettingsRepository,
459
+ db_1.AuthIdentityRepository,
460
+ url_service_1.UrlService,
461
+ config_1.GlobalConfig,
462
+ db_1.UserRepository,
463
+ n8n_core_1.Cipher,
464
+ backend_common_1.Logger,
465
+ jwt_service_1.JwtService,
466
+ n8n_core_1.InstanceSettings,
467
+ provisioning_service_ee_1.ProvisioningService])
468
+ ], OidcService);
@@ -0,0 +1,4 @@
1
+ import type { ModuleInterface } from '@n8n/decorators';
2
+ export declare class OidcModule implements ModuleInterface {
3
+ init(): Promise<void>;
4
+ }