@tsed/oidc-provider 8.11.0 → 8.11.2-rc.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 (112) hide show
  1. package/lib/esm/OidcModule.js +0 -1
  2. package/lib/esm/constants/constants.js +0 -1
  3. package/lib/esm/decorators/grantId.js +0 -1
  4. package/lib/esm/decorators/interaction.js +0 -1
  5. package/lib/esm/decorators/interactions.js +0 -1
  6. package/lib/esm/decorators/noCache.js +0 -1
  7. package/lib/esm/decorators/oidcCtx.js +0 -1
  8. package/lib/esm/decorators/oidcSession.js +0 -1
  9. package/lib/esm/decorators/params.js +0 -1
  10. package/lib/esm/decorators/prompt.js +0 -1
  11. package/lib/esm/decorators/uid.js +0 -1
  12. package/lib/esm/domain/InteractionMethods.js +0 -1
  13. package/lib/esm/domain/OidcAccountsMethods.js +0 -1
  14. package/lib/esm/domain/OidcBadInteractionName.js +0 -1
  15. package/lib/esm/domain/OidcInteractionMethods.js +0 -1
  16. package/lib/esm/domain/OidcInteractionOptions.js +0 -1
  17. package/lib/esm/domain/OidcInteractionPromptProps.js +0 -1
  18. package/lib/esm/domain/OidcSettings.js +0 -1
  19. package/lib/esm/domain/interfaces.js +0 -1
  20. package/lib/esm/index.js +0 -1
  21. package/lib/esm/middlewares/OidcInteractionMiddleware.js +0 -1
  22. package/lib/esm/middlewares/OidcNoCacheMiddleware.js +0 -1
  23. package/lib/esm/middlewares/OidcSecureMiddleware.js +0 -1
  24. package/lib/esm/services/OidcAdapters.js +0 -1
  25. package/lib/esm/services/OidcInteractionContext.js +0 -1
  26. package/lib/esm/services/OidcInteractions.js +0 -1
  27. package/lib/esm/services/OidcJwks.js +0 -1
  28. package/lib/esm/services/OidcPolicy.js +0 -1
  29. package/lib/esm/services/OidcProvider.js +0 -1
  30. package/lib/esm/utils/debug.js +0 -1
  31. package/lib/esm/utils/events.js +0 -1
  32. package/package.json +13 -10
  33. package/lib/esm/OidcModule.js.map +0 -1
  34. package/lib/esm/constants/constants.js.map +0 -1
  35. package/lib/esm/decorators/grantId.js.map +0 -1
  36. package/lib/esm/decorators/interaction.js.map +0 -1
  37. package/lib/esm/decorators/interactions.js.map +0 -1
  38. package/lib/esm/decorators/noCache.js.map +0 -1
  39. package/lib/esm/decorators/oidcCtx.js.map +0 -1
  40. package/lib/esm/decorators/oidcSession.js.map +0 -1
  41. package/lib/esm/decorators/params.js.map +0 -1
  42. package/lib/esm/decorators/prompt.js.map +0 -1
  43. package/lib/esm/decorators/uid.js.map +0 -1
  44. package/lib/esm/domain/InteractionMethods.js.map +0 -1
  45. package/lib/esm/domain/OidcAccountsMethods.js.map +0 -1
  46. package/lib/esm/domain/OidcBadInteractionName.js.map +0 -1
  47. package/lib/esm/domain/OidcInteractionMethods.js.map +0 -1
  48. package/lib/esm/domain/OidcInteractionOptions.js.map +0 -1
  49. package/lib/esm/domain/OidcInteractionPromptProps.js.map +0 -1
  50. package/lib/esm/domain/OidcSettings.js.map +0 -1
  51. package/lib/esm/domain/interfaces.js.map +0 -1
  52. package/lib/esm/index.js.map +0 -1
  53. package/lib/esm/middlewares/OidcInteractionMiddleware.js.map +0 -1
  54. package/lib/esm/middlewares/OidcNoCacheMiddleware.js.map +0 -1
  55. package/lib/esm/middlewares/OidcSecureMiddleware.js.map +0 -1
  56. package/lib/esm/services/OidcAdapters.js.map +0 -1
  57. package/lib/esm/services/OidcInteractionContext.js.map +0 -1
  58. package/lib/esm/services/OidcInteractions.js.map +0 -1
  59. package/lib/esm/services/OidcJwks.js.map +0 -1
  60. package/lib/esm/services/OidcPolicy.js.map +0 -1
  61. package/lib/esm/services/OidcProvider.js.map +0 -1
  62. package/lib/esm/utils/debug.js.map +0 -1
  63. package/lib/esm/utils/events.js.map +0 -1
  64. package/src/OidcModule.spec.ts +0 -116
  65. package/src/OidcModule.ts +0 -70
  66. package/src/constants/constants.ts +0 -10
  67. package/src/decorators/grantId.spec.ts +0 -17
  68. package/src/decorators/grantId.ts +0 -10
  69. package/src/decorators/interaction.spec.ts +0 -27
  70. package/src/decorators/interaction.ts +0 -18
  71. package/src/decorators/interactions.spec.ts +0 -23
  72. package/src/decorators/interactions.ts +0 -21
  73. package/src/decorators/noCache.ts +0 -7
  74. package/src/decorators/oidcCtx.spec.ts +0 -17
  75. package/src/decorators/oidcCtx.ts +0 -11
  76. package/src/decorators/oidcSession.spec.ts +0 -17
  77. package/src/decorators/oidcSession.ts +0 -14
  78. package/src/decorators/params.spec.ts +0 -17
  79. package/src/decorators/params.ts +0 -10
  80. package/src/decorators/prompt.spec.ts +0 -17
  81. package/src/decorators/prompt.ts +0 -11
  82. package/src/decorators/uid.spec.ts +0 -17
  83. package/src/decorators/uid.ts +0 -10
  84. package/src/domain/InteractionMethods.ts +0 -11
  85. package/src/domain/OidcAccountsMethods.ts +0 -10
  86. package/src/domain/OidcBadInteractionName.ts +0 -3
  87. package/src/domain/OidcInteractionMethods.ts +0 -3
  88. package/src/domain/OidcInteractionOptions.ts +0 -8
  89. package/src/domain/OidcInteractionPromptProps.ts +0 -11
  90. package/src/domain/OidcSettings.ts +0 -72
  91. package/src/domain/interfaces.ts +0 -13
  92. package/src/index.ts +0 -33
  93. package/src/middlewares/OidcInteractionMiddleware.spec.ts +0 -40
  94. package/src/middlewares/OidcInteractionMiddleware.ts +0 -14
  95. package/src/middlewares/OidcNoCacheMiddleware.spec.ts +0 -18
  96. package/src/middlewares/OidcNoCacheMiddleware.ts +0 -10
  97. package/src/middlewares/OidcSecureMiddleware.spec.ts +0 -106
  98. package/src/middlewares/OidcSecureMiddleware.ts +0 -30
  99. package/src/services/OidcAdapters.spec.ts +0 -100
  100. package/src/services/OidcAdapters.ts +0 -92
  101. package/src/services/OidcInteractionContext.spec.ts +0 -304
  102. package/src/services/OidcInteractionContext.ts +0 -206
  103. package/src/services/OidcInteractions.ts +0 -57
  104. package/src/services/OidcJwks.ts +0 -22
  105. package/src/services/OidcPolicy.spec.ts +0 -156
  106. package/src/services/OidcPolicy.ts +0 -92
  107. package/src/services/OidcProvider.spec.ts +0 -116
  108. package/src/services/OidcProvider.ts +0 -198
  109. package/src/utils/debug.spec.ts +0 -12
  110. package/src/utils/debug.ts +0 -26
  111. package/src/utils/events.ts +0 -61
  112. package/vitest.config.mts +0 -21
@@ -1,198 +0,0 @@
1
- import {Env, setValue} from "@tsed/core";
2
- import {constant, context, inject, Injectable, InjectorService} from "@tsed/di";
3
- import {PlatformApplication, PlatformContext} from "@tsed/platform-http";
4
- import Provider, {type Configuration, type KoaContextWithOIDC} from "oidc-provider";
5
-
6
- import {INTERACTIONS} from "../constants/constants.js";
7
- import {OidcAccountsMethods} from "../domain/OidcAccountsMethods.js";
8
- import {OidcSettings} from "../domain/OidcSettings.js";
9
- import {OIDC_ERROR_EVENTS} from "../utils/events.js";
10
- import {OidcAdapters} from "./OidcAdapters.js";
11
- import {OidcJwks} from "./OidcJwks.js";
12
- import {OidcPolicy} from "./OidcPolicy.js";
13
-
14
- function mapError(error: any) {
15
- return Object.getOwnPropertyNames(error).reduce((obj: any, key) => {
16
- return {
17
- ...obj,
18
- [key]: error[key]
19
- };
20
- }, {});
21
- }
22
-
23
- @Injectable()
24
- export class OidcProvider {
25
- raw: Provider;
26
-
27
- protected env = constant<Env>("env");
28
- protected httpPort = constant<number | string>("httpPort");
29
- protected httpsPort = constant<number | string>("httpsPort");
30
- protected issuer = constant<string>("oidc.issuer", "");
31
- protected oidc = constant<OidcSettings>("oidc")!;
32
- protected platformName = constant<string>("PLATFORM_NAME");
33
- protected oidcJwks = inject(OidcJwks);
34
- protected oidcPolicy = inject(OidcPolicy);
35
- protected adapters = inject(OidcAdapters);
36
- protected injector = inject(InjectorService);
37
- protected app = inject(PlatformApplication);
38
-
39
- get logger() {
40
- return this.$ctx.logger;
41
- }
42
-
43
- protected get $ctx() {
44
- return context<PlatformContext>();
45
- }
46
-
47
- hasConfiguration() {
48
- return !!this.oidc;
49
- }
50
-
51
- async getConfiguration(): Promise<Configuration> {
52
- const [jwks, adapter] = await Promise.all([this.oidcJwks.getJwks(), this.adapters.createAdapterClass()]);
53
- const {
54
- issuer,
55
- jwksPath,
56
- secureKey,
57
- proxy,
58
- Accounts,
59
- secureCookies = this.env == Env.PROD,
60
- Adapter,
61
- connectionName,
62
- render,
63
- ...options
64
- } = this.oidc;
65
-
66
- const configuration: Configuration = {
67
- interactions: {
68
- /* istanbul ignore next */
69
- url: (ctx, interaction) => `interaction/${interaction.uid}`
70
- },
71
- ...options,
72
- adapter,
73
- jwks
74
- };
75
-
76
- if (Accounts) {
77
- configuration.findAccount = (ctx, id, token) => this.injector.get<OidcAccountsMethods>(Accounts)!.findAccount(id, token);
78
- }
79
-
80
- if (secureCookies) {
81
- setValue(configuration, "cookies.short.secure", true);
82
- setValue(configuration, "cookies.long.secure", true);
83
- }
84
-
85
- const policy = this.oidcPolicy.getPolicy();
86
-
87
- if (policy) {
88
- setValue(configuration, "interactions.policy", policy);
89
- }
90
-
91
- const url = this.getInteractionsUrl();
92
- if (url) {
93
- setValue(configuration, "interactions.url", url);
94
- }
95
-
96
- return configuration;
97
- }
98
-
99
- getIssuer() {
100
- if (this.issuer) {
101
- return this.issuer;
102
- }
103
-
104
- // istanbul ignore next
105
- if (this.httpsPort) {
106
- return `https://localhost:${this.httpsPort}`;
107
- }
108
-
109
- return `http://localhost:${this.httpPort}`;
110
- }
111
-
112
- get(): Provider {
113
- return this.raw;
114
- }
115
-
116
- /**
117
- * Create a new instance of OidcProvider
118
- */
119
- async create(): Promise<void | Provider> {
120
- const {proxy = this.env === Env.PROD, secureKey, allowHttpLocalhost = this.env !== Env.PROD} = this.oidc;
121
- const configuration = await this.getConfiguration();
122
-
123
- await this.injector.alterAsync("$alterOidcConfiguration", configuration);
124
-
125
- const oidcProvider = new Provider(this.getIssuer(), configuration);
126
-
127
- if (proxy) {
128
- // istanbul ignore next
129
- switch (this.platformName) {
130
- default:
131
- case "express":
132
- oidcProvider.proxy = true;
133
- break;
134
- case "koa":
135
- (this.app.rawApp as any).proxy = true;
136
- break;
137
- }
138
- }
139
-
140
- if (secureKey) {
141
- oidcProvider.app.keys = secureKey;
142
- }
143
-
144
- this.raw = oidcProvider;
145
-
146
- if (allowHttpLocalhost) {
147
- this.allowHttpLocalhost();
148
- }
149
-
150
- OIDC_ERROR_EVENTS.map((event) => {
151
- this.raw.on(event, this.createErrorHandler(event));
152
- });
153
-
154
- await this.injector.emit("$onCreateOIDC", this.raw);
155
-
156
- return this.raw;
157
- }
158
-
159
- private createErrorHandler(event: string) {
160
- return (ctx: KoaContextWithOIDC, error: any, accountId?: string, sid?: string) => {
161
- this.logger.error({
162
- event: "OIDC_ERROR",
163
- type: event,
164
- error: mapError(error),
165
- account_id: accountId,
166
- params: ctx.oidc.params,
167
- headers: ctx.headers,
168
- sid
169
- });
170
-
171
- // TODO see if we need to call platformExceptions
172
- // this.platformExceptions.catch(error, ctx.request.$ctx);
173
- };
174
- }
175
-
176
- private getInteractionsUrl() {
177
- const provider = this.injector.getProviders().find((provider) => provider.subType === INTERACTIONS);
178
-
179
- if (provider) {
180
- return (ctx: any, interaction: any) => {
181
- return provider.path.replace(/:uid/, interaction.uid);
182
- };
183
- }
184
- }
185
-
186
- private allowHttpLocalhost() {
187
- const {invalidate: orig} = (this.raw.Client as any).Schema.prototype;
188
-
189
- (this.raw.Client as any).Schema.prototype.invalidate = function invalidate(message: string, code: string) {
190
- if (code === "implicit-force-https" || code === "implicit-forbid-localhost") {
191
- return;
192
- }
193
-
194
- /* istanbul ignore next */
195
- return orig.call(this, message);
196
- };
197
- }
198
- }
@@ -1,12 +0,0 @@
1
- import {debug} from "./debug.js";
2
-
3
- describe("debug", () => {
4
- it("should debug", () => {
5
- expect(
6
- debug({
7
- value: undefined,
8
- test: "1"
9
- })
10
- ).toEqual("<strong>test</strong>: '1'");
11
- });
12
- });
@@ -1,26 +0,0 @@
1
- import qs from "node:querystring";
2
- import {inspect} from "node:util";
3
-
4
- import {isEmpty} from "@tsed/core";
5
-
6
- const keys = new Set();
7
-
8
- function serialize(obj: any) {
9
- return Object.entries(obj).reduce((acc: any, [key, value]) => {
10
- keys.add(key);
11
-
12
- if (isEmpty(value)) {
13
- return acc;
14
- }
15
-
16
- acc[key] = inspect(value, {depth: null});
17
- return acc;
18
- }, {});
19
- }
20
-
21
- export const debug = (obj: any) =>
22
- qs.stringify(serialize(obj), "<br/>", ": ", {
23
- encodeURIComponent(value) {
24
- return keys.has(value) ? `<strong>${value}</strong>` : value;
25
- }
26
- });
@@ -1,61 +0,0 @@
1
- /**
2
- * Exports all OIDC providers events
3
- */
4
- export const OIDC_EVENTS = [
5
- "access_token.destroyed",
6
- "access_token.saved",
7
- "access_token.issued",
8
- "authorization_code.consumed",
9
- "authorization_code.destroyed",
10
- "authorization_code.saved",
11
- "authorization.accepted",
12
- "authorization.error",
13
- "authorization.success",
14
- "backchannel.error",
15
- "backchannel.success",
16
- "jwks.error",
17
- "client_credentials.destroyed",
18
- "client_credentials.saved",
19
- "client_credentials.issued",
20
- "device_code.consumed",
21
- "device_code.destroyed",
22
- "device_code.saved",
23
- "discovery.error",
24
- "end_session.error",
25
- "end_session.success",
26
- "grant.error",
27
- "grant.revoked",
28
- "grant.success",
29
- "initial_access_token.destroyed",
30
- "initial_access_token.saved",
31
- "interaction.destroyed",
32
- "interaction.ended",
33
- "interaction.saved",
34
- "interaction.started",
35
- "introspection.error",
36
- "replay_detection.destroyed",
37
- "replay_detection.saved",
38
- "pushed_authorization_request.error",
39
- "pushed_authorization_request.success",
40
- "pushed_authorization_request.destroyed",
41
- "pushed_authorization_request.saved",
42
- "refresh_token.consumed",
43
- "refresh_token.destroyed",
44
- "refresh_token.saved",
45
- "registration_access_token.destroyed",
46
- "registration_access_token.saved",
47
- "registration_create.error",
48
- "registration_create.success",
49
- "registration_delete.error",
50
- "registration_delete.success",
51
- "registration_read.error",
52
- "registration_update.error",
53
- "registration_update.success",
54
- "revocation.error",
55
- "server_error",
56
- "session.destroyed",
57
- "session.saved",
58
- "userinfo.error"
59
- ];
60
-
61
- export const OIDC_ERROR_EVENTS = OIDC_EVENTS.filter((e) => e.includes("error"));
package/vitest.config.mts DELETED
@@ -1,21 +0,0 @@
1
- // @ts-ignore
2
- import {presets} from "@tsed/vitest/presets";
3
- import {defineConfig} from "vitest/config";
4
-
5
- export default defineConfig(
6
- {
7
- ...presets,
8
- test: {
9
- ...presets.test,
10
- coverage: {
11
- ...presets.test.coverage,
12
- thresholds: {
13
- statements: 0,
14
- branches: 0,
15
- functions: 0,
16
- lines: 0
17
- }
18
- }
19
- }
20
- }
21
- );