@nauth-toolkit/oidc-provider 0.4.0 → 0.5.0

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.
@@ -9,4 +9,6 @@ export type { InteractionStateDTO, InteractionRedirectDTO } from '../src/interac
9
9
  export { OIDCSessionTerminator } from '../src/session-termination';
10
10
  export { createOIDCRateLimiter } from '../src/rate-limit';
11
11
  export type { OIDCRateLimitConfig } from '../src/rate-limit';
12
+ export { OIDCSelfMountService, NAUTH_OIDC_MOUNT_OPTIONS } from './self-mount.service';
13
+ export type { OIDCSelfMountOptions } from './self-mount.service';
12
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../nestjs/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,YAAY,EAAE,yBAAyB,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AACrG,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AACvF,OAAO,EAAE,+BAA+B,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAC1G,YAAY,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAIhD,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,YAAY,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAC7F,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,YAAY,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../nestjs/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,YAAY,EAAE,yBAAyB,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AACrG,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AACvF,OAAO,EAAE,+BAA+B,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAC1G,YAAY,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAIhD,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,YAAY,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAC7F,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,YAAY,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AACtF,YAAY,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createOIDCRateLimiter = exports.OIDCSessionTerminator = exports.OIDCInteractionBridge = exports.mountOIDCProviderNest = exports.DEFAULT_INTERACTION_PATH = exports.createOIDCInteractionController = exports.NAUTH_OIDC_SESSIONS = exports.NAUTH_OIDC_BRIDGE = exports.NAUTH_OIDC_PROVIDER = exports.OIDCProviderModule = void 0;
3
+ exports.NAUTH_OIDC_MOUNT_OPTIONS = exports.OIDCSelfMountService = exports.createOIDCRateLimiter = exports.OIDCSessionTerminator = exports.OIDCInteractionBridge = exports.mountOIDCProviderNest = exports.DEFAULT_INTERACTION_PATH = exports.createOIDCInteractionController = exports.NAUTH_OIDC_SESSIONS = exports.NAUTH_OIDC_BRIDGE = exports.NAUTH_OIDC_PROVIDER = exports.OIDCProviderModule = void 0;
4
4
  var oidc_provider_module_1 = require("./oidc-provider.module");
5
5
  Object.defineProperty(exports, "OIDCProviderModule", { enumerable: true, get: function () { return oidc_provider_module_1.OIDCProviderModule; } });
6
6
  var tokens_1 = require("./tokens");
@@ -20,4 +20,7 @@ var session_termination_1 = require("../src/session-termination");
20
20
  Object.defineProperty(exports, "OIDCSessionTerminator", { enumerable: true, get: function () { return session_termination_1.OIDCSessionTerminator; } });
21
21
  var rate_limit_1 = require("../src/rate-limit");
22
22
  Object.defineProperty(exports, "createOIDCRateLimiter", { enumerable: true, get: function () { return rate_limit_1.createOIDCRateLimiter; } });
23
+ var self_mount_service_1 = require("./self-mount.service");
24
+ Object.defineProperty(exports, "OIDCSelfMountService", { enumerable: true, get: function () { return self_mount_service_1.OIDCSelfMountService; } });
25
+ Object.defineProperty(exports, "NAUTH_OIDC_MOUNT_OPTIONS", { enumerable: true, get: function () { return self_mount_service_1.NAUTH_OIDC_MOUNT_OPTIONS; } });
23
26
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../nestjs/index.ts"],"names":[],"mappings":";;;AAAA,+DAA4D;AAAnD,0HAAA,kBAAkB,OAAA;AAE3B,mCAAuF;AAA9E,6GAAA,mBAAmB,OAAA;AAAE,2GAAA,iBAAiB,OAAA;AAAE,6GAAA,mBAAmB,OAAA;AACpE,6EAA0G;AAAjG,8IAAA,+BAA+B,OAAA;AAAE,uIAAA,wBAAwB,OAAA;AAElE,iCAAgD;AAAvC,8GAAA,qBAAqB,OAAA;AAE9B,gFAAgF;AAChF,8CAA8C;AAC9C,gEAAkE;AAAzD,2HAAA,qBAAqB,OAAA;AAE9B,kEAAmE;AAA1D,4HAAA,qBAAqB,OAAA;AAC9B,gDAA0D;AAAjD,mHAAA,qBAAqB,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../nestjs/index.ts"],"names":[],"mappings":";;;AAAA,+DAA4D;AAAnD,0HAAA,kBAAkB,OAAA;AAE3B,mCAAuF;AAA9E,6GAAA,mBAAmB,OAAA;AAAE,2GAAA,iBAAiB,OAAA;AAAE,6GAAA,mBAAmB,OAAA;AACpE,6EAA0G;AAAjG,8IAAA,+BAA+B,OAAA;AAAE,uIAAA,wBAAwB,OAAA;AAElE,iCAAgD;AAAvC,8GAAA,qBAAqB,OAAA;AAE9B,gFAAgF;AAChF,8CAA8C;AAC9C,gEAAkE;AAAzD,2HAAA,qBAAqB,OAAA;AAE9B,kEAAmE;AAA1D,4HAAA,qBAAqB,OAAA;AAC9B,gDAA0D;AAAjD,mHAAA,qBAAqB,OAAA;AAE9B,2DAAsF;AAA7E,0HAAA,oBAAoB,OAAA;AAAE,8HAAA,wBAAwB,OAAA"}
@@ -6,25 +6,34 @@ interface NestAppLike {
6
6
  };
7
7
  }
8
8
  /**
9
- * Attach an OpenID Connect provider to a NestJS application.
9
+ * Attach an OpenID Connect provider to a NestJS application by hand.
10
10
  *
11
- * Call this in `main.ts` **before** `app.use(json())` and before `setGlobalPrefix`.
12
- * The provider is attached to the underlying platform instance, not to Nest's router,
13
- * so it deliberately bypasses guards, interceptors, pipes and filters — it speaks
14
- * OAuth on its own paths and has nothing to gain from nauth's request pipeline. The
15
- * interaction bridge, which *does* need nauth's context, is an ordinary Nest
16
- * controller instead.
11
+ * **You almost certainly do not need this.** `OIDCProviderModule.forRoot()` mounts the
12
+ * provider itself during module initialisation, so a typical application has no
13
+ * OpenID Connect code in `main.ts` at all. This is the companion to
14
+ * `mount: { enabled: false }`, for the rare case where you must control the ordering —
15
+ * for example to place other raw middleware between the parser and the provider.
16
+ *
17
+ * Call it **before** `app.use(json())` and before `setGlobalPrefix`. The provider is
18
+ * attached to the underlying platform instance, not to Nest's router, so it
19
+ * deliberately bypasses guards, interceptors, pipes and filters — it speaks OAuth on
20
+ * its own paths and has nothing to gain from nauth's request pipeline. The interaction
21
+ * bridge, which *does* need nauth's context, is an ordinary Nest controller instead.
17
22
  *
18
23
  * Because the mount is on the platform instance, `setGlobalPrefix('api')` does not
19
24
  * apply to it: the provider's endpoints sit at the origin root exactly as its
20
25
  * discovery document advertises them.
21
26
  *
27
+ * Express-family drivers only. On Fastify, leave the module to mount itself — it
28
+ * routes through the platform adapter, which knows to use an `onRequest` hook.
29
+ *
22
30
  * @param app - The Nest application
23
31
  * @param provider - A configured provider
24
32
  * @param options - The path prefix its routes were configured with
25
33
  *
26
34
  * @example
27
35
  * ```typescript
36
+ * // Only alongside OIDCProviderModule.forRoot({ ..., mount: { enabled: false } })
28
37
  * const app = await NestFactory.create(AppModule, new ExpressAdapter());
29
38
  * mountOIDCProviderNest(app, app.get(NAUTH_OIDC_PROVIDER));
30
39
  * app.use(cookieParser());
@@ -1 +1 @@
1
- {"version":3,"file":"mount.d.ts","sourceRoot":"","sources":["../../nestjs/mount.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAG1C,yDAAyD;AACzD,UAAU,WAAW;IACnB,cAAc,IAAI;QAAE,WAAW,IAAI,OAAO,CAAA;KAAE,CAAC;CAC9C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,WAAW,EAChB,QAAQ,EAAE,QAAQ,EAClB,OAAO,GAAE;IAAE,UAAU,CAAC,EAAE,MAAM,CAAA;CAAO,GACpC,IAAI,CAKN"}
1
+ {"version":3,"file":"mount.d.ts","sourceRoot":"","sources":["../../nestjs/mount.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAG1C,yDAAyD;AACzD,UAAU,WAAW;IACnB,cAAc,IAAI;QAAE,WAAW,IAAI,OAAO,CAAA;KAAE,CAAC;CAC9C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,WAAW,EAChB,QAAQ,EAAE,QAAQ,EAClB,OAAO,GAAE;IAAE,UAAU,CAAC,EAAE,MAAM,CAAA;CAAO,GACpC,IAAI,CAKN"}
@@ -3,25 +3,34 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.mountOIDCProviderNest = mountOIDCProviderNest;
4
4
  const express_1 = require("../src/mount/express");
5
5
  /**
6
- * Attach an OpenID Connect provider to a NestJS application.
6
+ * Attach an OpenID Connect provider to a NestJS application by hand.
7
7
  *
8
- * Call this in `main.ts` **before** `app.use(json())` and before `setGlobalPrefix`.
9
- * The provider is attached to the underlying platform instance, not to Nest's router,
10
- * so it deliberately bypasses guards, interceptors, pipes and filters — it speaks
11
- * OAuth on its own paths and has nothing to gain from nauth's request pipeline. The
12
- * interaction bridge, which *does* need nauth's context, is an ordinary Nest
13
- * controller instead.
8
+ * **You almost certainly do not need this.** `OIDCProviderModule.forRoot()` mounts the
9
+ * provider itself during module initialisation, so a typical application has no
10
+ * OpenID Connect code in `main.ts` at all. This is the companion to
11
+ * `mount: { enabled: false }`, for the rare case where you must control the ordering —
12
+ * for example to place other raw middleware between the parser and the provider.
13
+ *
14
+ * Call it **before** `app.use(json())` and before `setGlobalPrefix`. The provider is
15
+ * attached to the underlying platform instance, not to Nest's router, so it
16
+ * deliberately bypasses guards, interceptors, pipes and filters — it speaks OAuth on
17
+ * its own paths and has nothing to gain from nauth's request pipeline. The interaction
18
+ * bridge, which *does* need nauth's context, is an ordinary Nest controller instead.
14
19
  *
15
20
  * Because the mount is on the platform instance, `setGlobalPrefix('api')` does not
16
21
  * apply to it: the provider's endpoints sit at the origin root exactly as its
17
22
  * discovery document advertises them.
18
23
  *
24
+ * Express-family drivers only. On Fastify, leave the module to mount itself — it
25
+ * routes through the platform adapter, which knows to use an `onRequest` hook.
26
+ *
19
27
  * @param app - The Nest application
20
28
  * @param provider - A configured provider
21
29
  * @param options - The path prefix its routes were configured with
22
30
  *
23
31
  * @example
24
32
  * ```typescript
33
+ * // Only alongside OIDCProviderModule.forRoot({ ..., mount: { enabled: false } })
25
34
  * const app = await NestFactory.create(AppModule, new ExpressAdapter());
26
35
  * mountOIDCProviderNest(app, app.get(NAUTH_OIDC_PROVIDER));
27
36
  * app.use(cookieParser());
@@ -1 +1 @@
1
- {"version":3,"file":"mount.js","sourceRoot":"","sources":["../../nestjs/mount.ts"],"names":[],"mappings":";;AAkCA,sDASC;AA1CD,kDAAgE;AAOhE;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,SAAgB,qBAAqB,CACnC,GAAgB,EAChB,QAAkB,EAClB,UAAmC,EAAE;IAErC,MAAM,QAAQ,GAAG,GAAG,CAAC,cAAc,EAAE,CAAC,WAAW,EAEhD,CAAC;IACF,IAAA,kCAAwB,EAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;AACxD,CAAC"}
1
+ {"version":3,"file":"mount.js","sourceRoot":"","sources":["../../nestjs/mount.ts"],"names":[],"mappings":";;AA2CA,sDASC;AAnDD,kDAAgE;AAOhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,SAAgB,qBAAqB,CACnC,GAAgB,EAChB,QAAkB,EAClB,UAAmC,EAAE;IAErC,MAAM,QAAQ,GAAG,GAAG,CAAC,cAAc,EAAE,CAAC,WAAW,EAEhD,CAAC;IACF,IAAA,kCAAwB,EAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;AACxD,CAAC"}
@@ -1,4 +1,5 @@
1
1
  import { DynamicModule } from '@nestjs/common';
2
+ import { type OIDCRateLimitConfig } from '../src/rate-limit';
2
3
  import type { NAuthOIDCOptions } from '../src/config.types';
3
4
  import { NAUTH_OIDC_BRIDGE, NAUTH_OIDC_PROVIDER, NAUTH_OIDC_SESSIONS } from './tokens';
4
5
  export { NAUTH_OIDC_BRIDGE, NAUTH_OIDC_PROVIDER, NAUTH_OIDC_SESSIONS };
@@ -35,27 +36,57 @@ export interface OIDCInteractionRouteOptions {
35
36
  export type OIDCProviderModuleOptions = Omit<NAuthOIDCOptions, 'storage' | 'userRepository'> & {
36
37
  /** How the interaction routes are registered. */
37
38
  interaction?: OIDCInteractionRouteOptions;
39
+ /**
40
+ * How the provider's own protocol endpoints are attached to the HTTP server.
41
+ *
42
+ * By default the module mounts them itself during initialisation, so `main.ts` needs
43
+ * no OpenID Connect code at all. Set `enabled: false` only if you must control the
44
+ * ordering yourself.
45
+ */
46
+ mount?: {
47
+ /** @default true */
48
+ enabled?: boolean;
49
+ };
50
+ /**
51
+ * Rate limits for the provider's endpoints, applied ahead of it.
52
+ *
53
+ * `oidc-provider` ships none, and these endpoints sit outside nauth's guard chain, so
54
+ * nothing else covers them — `POST /token` is otherwise an unauthenticated
55
+ * brute-force surface against client secrets and authorization codes.
56
+ *
57
+ * The limiter is built here from the configured storage adapter, so this is plain
58
+ * configuration rather than a constructed middleware.
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * rateLimit: {
63
+ * authorize: { max: 60, windowSeconds: 60 },
64
+ * token: { max: 60, windowSeconds: 60 },
65
+ * introspection: { max: 600, windowSeconds: 60 },
66
+ * }
67
+ * ```
68
+ */
69
+ rateLimit?: OIDCRateLimitConfig;
38
70
  };
39
71
  /**
40
72
  * Registers an OpenID Connect provider alongside `AuthModule`.
41
73
  *
42
- * The provider itself is *not* mounted by this module — it owns raw HTTP and must be
43
- * attached to the underlying platform adapter in `main.ts`, before the body parsers.
44
- * See `mountOIDCProviderNest`. What this module contributes is the configured
45
- * provider instance and the interaction bridge, both injectable into your own
46
- * controllers.
74
+ * The module contributes three things, and needs nothing from `main.ts`:
47
75
  *
48
- * The interaction routes the consent screen talks to *are* registered here, as an
49
- * ordinary Nest controller at `oidc/interaction/:uid`. Set `interaction.enabled` to
50
- * false to supply your own, or `interaction.path` to move them.
76
+ * 1. **The provider's protocol endpoints**, attached to the HTTP server during module
77
+ * initialisation. They own raw HTTP and deliberately sit outside nauth's guard,
78
+ * interceptor and pipe chain — and outside any global prefix, so discovery stays at
79
+ * the origin root where the issuer advertises it. See `OIDCSelfMountService` for the
80
+ * ordering this depends on; set `mount.enabled` to false to attach them yourself.
81
+ * 2. **The interaction routes** the consent screen talks to, as an ordinary Nest
82
+ * controller at `oidc/interaction/:uid`. Set `interaction.enabled` to false to
83
+ * supply your own, or `interaction.path` to move them.
84
+ * 3. **The provider instance and interaction bridge**, injectable into your own code.
51
85
  *
52
86
  * @example
53
87
  * ```typescript
54
- * // app.module.ts
88
+ * // app.module.ts — that is the whole integration
55
89
  * imports: [AuthModule.forRoot(authConfig), OIDCProviderModule.forRoot(oidcConfig)]
56
- *
57
- * // main.ts — after create(), before app.use(json())
58
- * mountOIDCProviderNest(app, app.get(NAUTH_OIDC_PROVIDER));
59
90
  * ```
60
91
  */
61
92
  export declare class OIDCProviderModule {
@@ -1 +1 @@
1
- {"version":3,"file":"oidc-provider.module.d.ts","sourceRoot":"","sources":["../../nestjs/oidc-provider.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAA0C,MAAM,gBAAgB,CAAC;AAQvF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAGvF,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,CAAC;AAEvE;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C;;;;;;;OAOG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;;;;;;;OAQG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;GAKG;AACH,MAAM,MAAM,yBAAyB,GAAG,IAAI,CAAC,gBAAgB,EAAE,SAAS,GAAG,gBAAgB,CAAC,GAAG;IAC7F,iDAAiD;IACjD,WAAW,CAAC,EAAE,2BAA2B,CAAC;CAC3C,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBACa,kBAAkB;IAC7B;;;;;OAKG;IACH,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,yBAAyB,GAAG,aAAa;CAqClE"}
1
+ {"version":3,"file":"oidc-provider.module.d.ts","sourceRoot":"","sources":["../../nestjs/oidc-provider.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAA0C,MAAM,gBAAgB,CAAC;AAMvF,OAAO,EAAyB,KAAK,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAGpF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAIvF,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,CAAC;AAEvE;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C;;;;;;;OAOG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;;;;;;;OAQG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;GAKG;AACH,MAAM,MAAM,yBAAyB,GAAG,IAAI,CAAC,gBAAgB,EAAE,SAAS,GAAG,gBAAgB,CAAC,GAAG;IAC7F,iDAAiD;IACjD,WAAW,CAAC,EAAE,2BAA2B,CAAC;IAE1C;;;;;;OAMG;IACH,KAAK,CAAC,EAAE;QACN,oBAAoB;QACpB,OAAO,CAAC,EAAE,OAAO,CAAC;KACnB,CAAC;IAEF;;;;;;;;;;;;;;;;;;OAkBG;IACH,SAAS,CAAC,EAAE,mBAAmB,CAAC;CACjC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBACa,kBAAkB;IAC7B;;;;;OAKG;IACH,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,yBAAyB,GAAG,aAAa;CAwDlE"}
@@ -11,6 +11,7 @@ exports.OIDCProviderModule = exports.NAUTH_OIDC_SESSIONS = exports.NAUTH_OIDC_PR
11
11
  const common_1 = require("@nestjs/common");
12
12
  const internal_1 = require("@nauth-toolkit/core/internal");
13
13
  const create_provider_1 = require("../src/create-provider");
14
+ const rate_limit_1 = require("../src/rate-limit");
14
15
  const interaction_bridge_1 = require("../src/interaction-bridge");
15
16
  const session_termination_1 = require("../src/session-termination");
16
17
  const tokens_1 = require("./tokens");
@@ -18,26 +19,26 @@ Object.defineProperty(exports, "NAUTH_OIDC_BRIDGE", { enumerable: true, get: fun
18
19
  Object.defineProperty(exports, "NAUTH_OIDC_PROVIDER", { enumerable: true, get: function () { return tokens_1.NAUTH_OIDC_PROVIDER; } });
19
20
  Object.defineProperty(exports, "NAUTH_OIDC_SESSIONS", { enumerable: true, get: function () { return tokens_1.NAUTH_OIDC_SESSIONS; } });
20
21
  const oidc_interaction_controller_1 = require("./oidc-interaction.controller");
22
+ const self_mount_service_1 = require("./self-mount.service");
21
23
  /**
22
24
  * Registers an OpenID Connect provider alongside `AuthModule`.
23
25
  *
24
- * The provider itself is *not* mounted by this module — it owns raw HTTP and must be
25
- * attached to the underlying platform adapter in `main.ts`, before the body parsers.
26
- * See `mountOIDCProviderNest`. What this module contributes is the configured
27
- * provider instance and the interaction bridge, both injectable into your own
28
- * controllers.
26
+ * The module contributes three things, and needs nothing from `main.ts`:
29
27
  *
30
- * The interaction routes the consent screen talks to *are* registered here, as an
31
- * ordinary Nest controller at `oidc/interaction/:uid`. Set `interaction.enabled` to
32
- * false to supply your own, or `interaction.path` to move them.
28
+ * 1. **The provider's protocol endpoints**, attached to the HTTP server during module
29
+ * initialisation. They own raw HTTP and deliberately sit outside nauth's guard,
30
+ * interceptor and pipe chain — and outside any global prefix, so discovery stays at
31
+ * the origin root where the issuer advertises it. See `OIDCSelfMountService` for the
32
+ * ordering this depends on; set `mount.enabled` to false to attach them yourself.
33
+ * 2. **The interaction routes** the consent screen talks to, as an ordinary Nest
34
+ * controller at `oidc/interaction/:uid`. Set `interaction.enabled` to false to
35
+ * supply your own, or `interaction.path` to move them.
36
+ * 3. **The provider instance and interaction bridge**, injectable into your own code.
33
37
  *
34
38
  * @example
35
39
  * ```typescript
36
- * // app.module.ts
40
+ * // app.module.ts — that is the whole integration
37
41
  * imports: [AuthModule.forRoot(authConfig), OIDCProviderModule.forRoot(oidcConfig)]
38
- *
39
- * // main.ts — after create(), before app.use(json())
40
- * mountOIDCProviderNest(app, app.get(NAUTH_OIDC_PROVIDER));
41
42
  * ```
42
43
  */
43
44
  let OIDCProviderModule = OIDCProviderModule_1 = class OIDCProviderModule {
@@ -48,7 +49,10 @@ let OIDCProviderModule = OIDCProviderModule_1 = class OIDCProviderModule {
48
49
  * @returns A dynamic module exporting the provider and its interaction bridge
49
50
  */
50
51
  static forRoot(options) {
51
- const { interaction, ...providerOptions } = options;
52
+ // Module-level concerns are stripped here: everything remaining is spread into the
53
+ // provider's own configuration, which would reject keys it does not recognise.
54
+ const { interaction, mount, rateLimit, ...providerOptions } = options;
55
+ const pathPrefix = providerOptions.pathPrefix ?? '/oidc';
52
56
  const providerFactory = {
53
57
  provide: tokens_1.NAUTH_OIDC_PROVIDER,
54
58
  useFactory: async (storage, userRepository) => (0, create_provider_1.createNAuthOIDCProvider)({ ...providerOptions, storage, userRepository }),
@@ -69,10 +73,24 @@ let OIDCProviderModule = OIDCProviderModule_1 = class OIDCProviderModule {
69
73
  const controllers = interaction?.enabled === false
70
74
  ? []
71
75
  : [(0, oidc_interaction_controller_1.createOIDCInteractionController)(interaction?.path ?? oidc_interaction_controller_1.DEFAULT_INTERACTION_PATH)];
76
+ // The provider attaches itself to the HTTP server during module initialisation, so
77
+ // nothing about OpenID Connect needs to appear in main.ts. Opt out to attach it
78
+ // yourself - see OIDCSelfMountService for the ordering constraints that entails.
79
+ const mountOptionsProvider = {
80
+ provide: self_mount_service_1.NAUTH_OIDC_MOUNT_OPTIONS,
81
+ // Built from DI so the limiter can reach the configured storage adapter, which is
82
+ // why rate limiting is expressed as configuration rather than a middleware.
83
+ useFactory: (storage) => ({
84
+ pathPrefix,
85
+ rateLimiter: rateLimit ? (0, rate_limit_1.createOIDCRateLimiter)(storage, rateLimit, { pathPrefix }) : undefined,
86
+ }),
87
+ inject: ['STORAGE_ADAPTER'],
88
+ };
89
+ const selfMounts = options.mount?.enabled === false ? [] : [self_mount_service_1.OIDCSelfMountService];
72
90
  return {
73
91
  module: OIDCProviderModule_1,
74
92
  controllers,
75
- providers: [providerFactory, bridgeFactory, terminatorFactory],
93
+ providers: [providerFactory, bridgeFactory, terminatorFactory, mountOptionsProvider, ...selfMounts],
76
94
  exports: [tokens_1.NAUTH_OIDC_PROVIDER, tokens_1.NAUTH_OIDC_BRIDGE, tokens_1.NAUTH_OIDC_SESSIONS],
77
95
  };
78
96
  }
@@ -1 +1 @@
1
- {"version":3,"file":"oidc-provider.module.js","sourceRoot":"","sources":["../../nestjs/oidc-provider.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAuF;AAIvF,2DAAgF;AAChF,4DAAiE;AACjE,kEAAkE;AAClE,oEAAmE;AAEnE,qCAAuF;AAG9E,kGAHA,0BAAiB,OAGA;AAAE,oGAHA,4BAAmB,OAGA;AAAE,oGAHA,4BAAmB,OAGA;AAFpE,+EAA0G;AAyC1G;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEI,IAAM,kBAAkB,0BAAxB,MAAM,kBAAkB;IAC7B;;;;;OAKG;IACH,MAAM,CAAC,OAAO,CAAC,OAAkC;QAC/C,MAAM,EAAE,WAAW,EAAE,GAAG,eAAe,EAAE,GAAG,OAAO,CAAC;QAEpD,MAAM,eAAe,GAAiB;YACpC,OAAO,EAAE,4BAAmB;YAC5B,UAAU,EAAE,KAAK,EAAE,OAAuB,EAAE,cAAoC,EAAqB,EAAE,CACrG,IAAA,yCAAuB,EAAC,EAAE,GAAG,eAAe,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC;YAC1E,MAAM,EAAE,CAAC,iBAAiB,EAAE,gBA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C5B,CAAC;QAEF,MAAM,WAAW,GACf,WAAW,EAAE,OAAO,KAAK,KAAK;YAC5B,CAAC,CAAC,EAAE;YACJ,CAAC,CAAC,CAAC,IAAA,6DAA+B,EAAC,WAAW,EAAE,IAAI,IAAI,sDAAwB,CAAC,CAAC,CAAC;QAEvF,mFAAmF;QACnF,gFAAgF;QAChF,iFAAiF;QACjF,MAAM,oBAAoB,GAAiB;YACzC,OAAO,EAAE,6CAAwB;YACjC,kFAAkF;YAClF,4EAA4E;YAC5E,UAAU,EAAE,CAAC,OAAuB,EAAwB,EAAE,CAAC,CAAC;gBAC9D,UAAU;gBACV,WAAW,EAAE,SAAS,CAAC,CAAC,CAAC,IAAA,kCAAqB,EAAC,OAAO,EAAE,SAAS,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS;aAC/F,CAAC;YACF,MAAM,EAAE,CAAC,iBAAiB,CAAC;SAC5B,CAAC;QAEF,MAAM,UAAU,GAAG,OAAO,CAAC,KAAK,EAAE,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,yCAAoB,CAAC,CAAC;QAElF,OAAO;YACL,MAAM,EAAE,oBAAkB;YAC1B,WAAW;YACX,SAAS,EAAE,CAAC,eAAe,EAAE,aAAa,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,GAAG,UAAU,CAAC;YACnG,OAAO,EAAE,CAAC,4BAAmB,EAAE,0BAAiB,EAAE,4BAAmB,CAAC;SACvE,CAAC;IACJ,CAAC;CACF,CAAA;AA/DY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,kBAAkB,CA+D9B"}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Self-mounting for the OpenID Connect provider
3
+ *
4
+ * The provider's endpoints are raw HTTP: its handler is Koa's, arity `(req, res)` with
5
+ * no `next`, so it must own the request outright and sit outside Nest's routing. This
6
+ * service attaches it during module initialisation, which removes the hand-ordered
7
+ * bootstrapping that previously had to live in `main.ts`.
8
+ *
9
+ * @packageDocumentation
10
+ */
11
+ import { OnModuleInit } from '@nestjs/common';
12
+ import { HttpAdapterHost } from '@nestjs/core';
13
+ import type Provider from 'oidc-provider';
14
+ import type { IncomingMessage, ServerResponse } from 'node:http';
15
+ import { NAuthLogger, type NAuthAdapter } from '@nauth-toolkit/core';
16
+ /** Settings the self-mount needs, supplied by `OIDCProviderModule.forRoot()`. */
17
+ export interface OIDCSelfMountOptions {
18
+ /** Path prefix the provider's routes were configured with. */
19
+ pathPrefix: string;
20
+ /** Optional rate limiter, registered ahead of the provider. */
21
+ rateLimiter?: (req: IncomingMessage, res: ServerResponse, next: () => void) => void;
22
+ }
23
+ /** DI token carrying the self-mount settings. */
24
+ export declare const NAUTH_OIDC_MOUNT_OPTIONS = "NAUTH_OIDC_MOUNT_OPTIONS";
25
+ /**
26
+ * Attaches the provider to the running HTTP server.
27
+ *
28
+ * **Why `onModuleInit`, and why the raw driver.** `NestApplication.init()` runs
29
+ * `registerParserMiddleware` → `registerModules` → `registerRouter` → `callInitHook`
30
+ * → `registerRouterHooks`. This hook fires at `callInitHook`, which is:
31
+ *
32
+ * - *after* Nest's router, which is harmless — it calls `next()` when no controller
33
+ * matches, so provider paths fall through to us;
34
+ * - *before* the not-found handler, which is essential — one step later
35
+ * (`onApplicationBootstrap`) and every provider request would 404.
36
+ *
37
+ * Attaching to the raw driver rather than `MiddlewareConsumer` is equally deliberate:
38
+ * middleware routes are rewritten by `RouteInfoPathExtractor` to include the global
39
+ * prefix, which would move discovery off the origin root and break every URL the
40
+ * issuer advertises.
41
+ *
42
+ * The one cost, on Express only, is that the body arrives already parsed — the parser
43
+ * is registered before modules and ignores the global prefix. `oidc-provider` falls
44
+ * back to `req.body`, so this works; the provider's own request-size limit simply
45
+ * defers to the upstream parser's. Fastify has no such cost: its `onRequest` hook runs
46
+ * before body parsing.
47
+ */
48
+ export declare class OIDCSelfMountService implements OnModuleInit {
49
+ private readonly adapterHost;
50
+ private readonly provider;
51
+ private readonly options;
52
+ private readonly nauthAdapter?;
53
+ private readonly logger?;
54
+ constructor(adapterHost: HttpAdapterHost, provider: Provider, options: OIDCSelfMountOptions, nauthAdapter?: NAuthAdapter | undefined, logger?: NAuthLogger | undefined);
55
+ /**
56
+ * Pick the platform adapter matching the HTTP driver Nest is running on.
57
+ *
58
+ * Selection is by capability rather than by an injected token: under NestJS the core
59
+ * adapters are not part of the request pipeline at all, so nothing binds one, and
60
+ * depending on an injected `NAUTH_ADAPTER` left the Fastify path unreachable. A
61
+ * consumer that *does* bind one still wins.
62
+ *
63
+ * @param instance - The underlying HTTP instance from `HttpAdapterHost`
64
+ * @returns The adapter whose `mountRaw` suits this driver, or undefined if neither fits
65
+ */
66
+ private selectAdapter;
67
+ /**
68
+ * Register the rate limiter and provider on the underlying HTTP instance.
69
+ */
70
+ onModuleInit(): void;
71
+ }
72
+ //# sourceMappingURL=self-mount.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"self-mount.service.d.ts","sourceRoot":"","sources":["../../nestjs/self-mount.service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAsB,YAAY,EAAY,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACjE,OAAO,EAAkC,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAIrG,iFAAiF;AACjF,MAAM,WAAW,oBAAoB;IACnC,8DAA8D;IAC9D,UAAU,EAAE,MAAM,CAAC;IACnB,+DAA+D;IAC/D,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,IAAI,KAAK,IAAI,CAAC;CACrF;AAED,iDAAiD;AACjD,eAAO,MAAM,wBAAwB,6BAA6B,CAAC;AAEnE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBACa,oBAAqB,YAAW,YAAY;IAErD,OAAO,CAAC,QAAQ,CAAC,WAAW;IACC,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACpB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACrB,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC;IACvD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;gBAJnB,WAAW,EAAE,eAAe,EACC,QAAQ,EAAE,QAAQ,EACb,OAAO,EAAE,oBAAoB,EAC1B,YAAY,CAAC,EAAE,YAAY,YAAA,EACpD,MAAM,CAAC,EAAE,WAAW,YAAA;IAGnD;;;;;;;;;;OAUG;IACH,OAAO,CAAC,aAAa;IAWrB;;OAEG;IACH,YAAY,IAAI,IAAI;CAoCrB"}
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ /**
3
+ * Self-mounting for the OpenID Connect provider
4
+ *
5
+ * The provider's endpoints are raw HTTP: its handler is Koa's, arity `(req, res)` with
6
+ * no `next`, so it must own the request outright and sit outside Nest's routing. This
7
+ * service attaches it during module initialisation, which removes the hand-ordered
8
+ * bootstrapping that previously had to live in `main.ts`.
9
+ *
10
+ * @packageDocumentation
11
+ */
12
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
13
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
14
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
15
+ 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;
16
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
17
+ };
18
+ var __metadata = (this && this.__metadata) || function (k, v) {
19
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
20
+ };
21
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
22
+ return function (target, key) { decorator(target, key, paramIndex); }
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.OIDCSelfMountService = exports.NAUTH_OIDC_MOUNT_OPTIONS = void 0;
26
+ const common_1 = require("@nestjs/common");
27
+ const core_1 = require("@nestjs/core");
28
+ const core_2 = require("@nauth-toolkit/core");
29
+ const express_1 = require("../src/mount/express");
30
+ const tokens_1 = require("./tokens");
31
+ /** DI token carrying the self-mount settings. */
32
+ exports.NAUTH_OIDC_MOUNT_OPTIONS = 'NAUTH_OIDC_MOUNT_OPTIONS';
33
+ /**
34
+ * Attaches the provider to the running HTTP server.
35
+ *
36
+ * **Why `onModuleInit`, and why the raw driver.** `NestApplication.init()` runs
37
+ * `registerParserMiddleware` → `registerModules` → `registerRouter` → `callInitHook`
38
+ * → `registerRouterHooks`. This hook fires at `callInitHook`, which is:
39
+ *
40
+ * - *after* Nest's router, which is harmless — it calls `next()` when no controller
41
+ * matches, so provider paths fall through to us;
42
+ * - *before* the not-found handler, which is essential — one step later
43
+ * (`onApplicationBootstrap`) and every provider request would 404.
44
+ *
45
+ * Attaching to the raw driver rather than `MiddlewareConsumer` is equally deliberate:
46
+ * middleware routes are rewritten by `RouteInfoPathExtractor` to include the global
47
+ * prefix, which would move discovery off the origin root and break every URL the
48
+ * issuer advertises.
49
+ *
50
+ * The one cost, on Express only, is that the body arrives already parsed — the parser
51
+ * is registered before modules and ignores the global prefix. `oidc-provider` falls
52
+ * back to `req.body`, so this works; the provider's own request-size limit simply
53
+ * defers to the upstream parser's. Fastify has no such cost: its `onRequest` hook runs
54
+ * before body parsing.
55
+ */
56
+ let OIDCSelfMountService = class OIDCSelfMountService {
57
+ adapterHost;
58
+ provider;
59
+ options;
60
+ nauthAdapter;
61
+ logger;
62
+ constructor(adapterHost, provider, options, nauthAdapter, logger) {
63
+ this.adapterHost = adapterHost;
64
+ this.provider = provider;
65
+ this.options = options;
66
+ this.nauthAdapter = nauthAdapter;
67
+ this.logger = logger;
68
+ }
69
+ /**
70
+ * Pick the platform adapter matching the HTTP driver Nest is running on.
71
+ *
72
+ * Selection is by capability rather than by an injected token: under NestJS the core
73
+ * adapters are not part of the request pipeline at all, so nothing binds one, and
74
+ * depending on an injected `NAUTH_ADAPTER` left the Fastify path unreachable. A
75
+ * consumer that *does* bind one still wins.
76
+ *
77
+ * @param instance - The underlying HTTP instance from `HttpAdapterHost`
78
+ * @returns The adapter whose `mountRaw` suits this driver, or undefined if neither fits
79
+ */
80
+ selectAdapter(instance) {
81
+ if (this.nauthAdapter?.mountRaw)
82
+ return this.nauthAdapter;
83
+ // Fastify first: its instance also exposes other methods, but only it has addHook,
84
+ // and `use()` on Fastify needs the middie shim that may not be registered.
85
+ if (typeof instance.addHook === 'function')
86
+ return new core_2.FastifyAdapter();
87
+ if (typeof instance.use === 'function')
88
+ return new core_2.ExpressAdapter();
89
+ return undefined;
90
+ }
91
+ /**
92
+ * Register the rate limiter and provider on the underlying HTTP instance.
93
+ */
94
+ onModuleInit() {
95
+ const instance = this.adapterHost?.httpAdapter?.getInstance?.();
96
+ if (!instance) {
97
+ this.logger?.warn?.('OIDC self-mount skipped: no HTTP adapter instance available');
98
+ return;
99
+ }
100
+ const prefix = this.options.pathPrefix;
101
+ const callback = this.provider.callback();
102
+ const adapter = this.selectAdapter(instance);
103
+ if (!adapter?.mountRaw) {
104
+ this.logger?.warn?.('OIDC self-mount skipped: the HTTP driver exposes neither use() nor addHook(), ' +
105
+ 'so the provider could not be attached. Mount it yourself with mountOIDCProviderNest().');
106
+ return;
107
+ }
108
+ // The rate limiter runs inside the same claimed request rather than as a separate
109
+ // layer, so both drivers get it: on Fastify the socket is already hijacked by the
110
+ // time the handler runs, and a second hook could not intervene.
111
+ const limiter = this.options.rateLimiter;
112
+ const handler = limiter
113
+ ? (req, res) => {
114
+ limiter(req, res, () => callback(req, res));
115
+ }
116
+ : (req, res) => callback(req, res);
117
+ adapter.mountRaw(instance, (path) => (0, express_1.isProviderPath)({ path }, prefix), handler);
118
+ this.logger?.log?.(`OpenID Connect provider mounted at ${prefix} via ${adapter.name}`);
119
+ }
120
+ };
121
+ exports.OIDCSelfMountService = OIDCSelfMountService;
122
+ exports.OIDCSelfMountService = OIDCSelfMountService = __decorate([
123
+ (0, common_1.Injectable)(),
124
+ __param(1, (0, common_1.Inject)(tokens_1.NAUTH_OIDC_PROVIDER)),
125
+ __param(2, (0, common_1.Inject)(exports.NAUTH_OIDC_MOUNT_OPTIONS)),
126
+ __param(3, (0, common_1.Optional)()),
127
+ __param(3, (0, common_1.Inject)('NAUTH_ADAPTER')),
128
+ __param(4, (0, common_1.Optional)()),
129
+ __metadata("design:paramtypes", [core_1.HttpAdapterHost, Function, Object, Object, core_2.NAuthLogger])
130
+ ], OIDCSelfMountService);
131
+ //# sourceMappingURL=self-mount.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"self-mount.service.js","sourceRoot":"","sources":["../../nestjs/self-mount.service.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;;;;;;;;;;;;AAEH,2CAA4E;AAC5E,uCAA+C;AAG/C,8CAAqG;AACrG,kDAAsD;AACtD,qCAA+C;AAU/C,iDAAiD;AACpC,QAAA,wBAAwB,GAAG,0BAA0B,CAAC;AAEnE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEI,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAEZ;IAC6B;IACK;IACG;IACzB;IAL/B,YACmB,WAA4B,EACC,QAAkB,EACb,OAA6B,EAC1B,YAA2B,EACpD,MAAoB;QAJhC,gBAAW,GAAX,WAAW,CAAiB;QACC,aAAQ,GAAR,QAAQ,CAAU;QACb,YAAO,GAAP,OAAO,CAAsB;QAC1B,iBAAY,GAAZ,YAAY,CAAe;QACpD,WAAM,GAAN,MAAM,CAAc;IAChD,CAAC;IAEJ;;;;;;;;;;OAUG;IACK,aAAa,CAAC,Q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C;YACH,CAAC,CAAC,CAAC,GAAoB,EAAE,GAAmB,EAAQ,EAAE,CAAC,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAE5E,OAAO,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAA,wBAAc,EAAC,EAAE,IAAI,EAAE,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC;QAEhF,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,sCAAsC,MAAM,QAAQ,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;IACzF,CAAC;CACF,CAAA;AAtEY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,mBAAU,GAAE;IAIR,WAAA,IAAA,eAAM,EAAC,4BAAmB,CAAC,CAAA;IAC3B,WAAA,IAAA,eAAM,EAAC,gCAAwB,CAAC,CAAA;IAChC,WAAA,IAAA,iBAAQ,GAAE,CAAA;IAAE,WAAA,IAAA,eAAM,EAAC,eAAe,CAAC,CAAA;IACnC,WAAA,IAAA,iBAAQ,GAAE,CAAA;qCAJmB,sBAAe,4BAIP,kBAAW;GANxC,oBAAoB,CAsEhC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nauth-toolkit/oidc-provider",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "OpenID Connect provider for nauth-toolkit, backed by the OpenID Certified oidc-provider library",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",
@@ -35,10 +35,10 @@
35
35
  "format:check": "prettier --check \"src/**/*.ts\" \"nestjs/**/*.ts\""
36
36
  },
37
37
  "peerDependencies": {
38
- "@nauth-toolkit/core": "^0.4.0",
38
+ "@nauth-toolkit/core": "^0.5.0",
39
39
  "oidc-provider": "^9.0.0",
40
40
  "@nestjs/common": "^9.0.0 || ^10.0.0 || ^11.0.0",
41
- "@nauth-toolkit/nestjs": "^0.4.0"
41
+ "@nauth-toolkit/nestjs": "^0.5.0"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@types/node": "^22.0.0",