@nauth-toolkit/oidc-provider 0.4.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.
Files changed (64) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +158 -0
  3. package/dist/nestjs/index.d.ts +12 -0
  4. package/dist/nestjs/index.d.ts.map +1 -0
  5. package/dist/nestjs/index.js +23 -0
  6. package/dist/nestjs/index.js.map +1 -0
  7. package/dist/nestjs/mount.d.ts +38 -0
  8. package/dist/nestjs/mount.d.ts.map +1 -0
  9. package/dist/nestjs/mount.js +35 -0
  10. package/dist/nestjs/mount.js.map +1 -0
  11. package/dist/nestjs/oidc-interaction.controller.d.ts +40 -0
  12. package/dist/nestjs/oidc-interaction.controller.d.ts.map +1 -0
  13. package/dist/nestjs/oidc-interaction.controller.js +157 -0
  14. package/dist/nestjs/oidc-interaction.controller.js.map +1 -0
  15. package/dist/nestjs/oidc-provider.module.d.ts +70 -0
  16. package/dist/nestjs/oidc-provider.module.d.ts.map +1 -0
  17. package/dist/nestjs/oidc-provider.module.js +84 -0
  18. package/dist/nestjs/oidc-provider.module.js.map +1 -0
  19. package/dist/nestjs/tokens.d.ts +13 -0
  20. package/dist/nestjs/tokens.d.ts.map +1 -0
  21. package/dist/nestjs/tokens.js +16 -0
  22. package/dist/nestjs/tokens.js.map +1 -0
  23. package/dist/src/config.types.d.ts +102 -0
  24. package/dist/src/config.types.d.ts.map +1 -0
  25. package/dist/src/config.types.js +3 -0
  26. package/dist/src/config.types.js.map +1 -0
  27. package/dist/src/create-provider.d.ts +47 -0
  28. package/dist/src/create-provider.d.ts.map +1 -0
  29. package/dist/src/create-provider.js +159 -0
  30. package/dist/src/create-provider.js.map +1 -0
  31. package/dist/src/find-account.d.ts +33 -0
  32. package/dist/src/find-account.d.ts.map +1 -0
  33. package/dist/src/find-account.js +69 -0
  34. package/dist/src/find-account.js.map +1 -0
  35. package/dist/src/index.d.ts +41 -0
  36. package/dist/src/index.d.ts.map +1 -0
  37. package/dist/src/index.js +51 -0
  38. package/dist/src/index.js.map +1 -0
  39. package/dist/src/interaction-bridge.d.ts +147 -0
  40. package/dist/src/interaction-bridge.d.ts.map +1 -0
  41. package/dist/src/interaction-bridge.js +283 -0
  42. package/dist/src/interaction-bridge.js.map +1 -0
  43. package/dist/src/mount/express.d.ts +54 -0
  44. package/dist/src/mount/express.d.ts.map +1 -0
  45. package/dist/src/mount/express.js +56 -0
  46. package/dist/src/mount/express.js.map +1 -0
  47. package/dist/src/rate-limit.d.ts +61 -0
  48. package/dist/src/rate-limit.d.ts.map +1 -0
  49. package/dist/src/rate-limit.js +93 -0
  50. package/dist/src/rate-limit.js.map +1 -0
  51. package/dist/src/raw-http.d.ts +25 -0
  52. package/dist/src/raw-http.d.ts.map +1 -0
  53. package/dist/src/raw-http.js +33 -0
  54. package/dist/src/raw-http.js.map +1 -0
  55. package/dist/src/session-termination.d.ts +60 -0
  56. package/dist/src/session-termination.d.ts.map +1 -0
  57. package/dist/src/session-termination.js +70 -0
  58. package/dist/src/session-termination.js.map +1 -0
  59. package/dist/src/storage.adapter.d.ts +99 -0
  60. package/dist/src/storage.adapter.d.ts.map +1 -0
  61. package/dist/src/storage.adapter.js +197 -0
  62. package/dist/src/storage.adapter.js.map +1 -0
  63. package/dist/tsconfig.tsbuildinfo +1 -0
  64. package/package.json +95 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Noorix Digital Solutions
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,158 @@
1
+ # @nauth-toolkit/oidc-provider
2
+
3
+ Turn an nauth-toolkit application into an OAuth 2.0 authorization server and OpenID Connect provider, so third parties can offer "Sign in with your app".
4
+
5
+ The protocol is implemented by [`oidc-provider`](https://github.com/panva/node-oidc-provider) — OpenID Certified, MIT, no commercial tier. This package supplies the three things it needs from nauth and nothing else: **storage**, **accounts**, and a **login and consent flow**. nauth owns no protocol code.
6
+
7
+ Full guide: <https://nauth.dev>
8
+
9
+ ## Why this shape
10
+
11
+ nauth stays the sole authority on identity. When the provider needs a user, it redirects to your application; your existing login runs — forced password change, email and phone verification, MFA setup and verification, adaptive risk — and only then does the interaction bridge report a completed login. No challenge component changes.
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ npm install @nauth-toolkit/oidc-provider oidc-provider
17
+ ```
18
+
19
+ `oidc-provider` is a peer dependency, so you control its version. It is ESM-only; Node 22.12+ loads it directly, and older versions fall back to a dynamic import automatically.
20
+
21
+ ## Express
22
+
23
+ ```ts
24
+ import { createNAuthOIDCProvider, mountOIDCProviderExpress } from '@nauth-toolkit/oidc-provider';
25
+
26
+ const provider = await createNAuthOIDCProvider({
27
+ issuer: 'https://app.example.com', // an origin — see the warning below
28
+ pathPrefix: '/oidc',
29
+ interactionUrl: (uid) => `https://app.example.com/interaction/${uid}`,
30
+ storage: nauth.storage,
31
+ userRepository,
32
+ cookieKeys: [process.env.OIDC_COOKIE_SECRET!],
33
+ proxy: true, // behind a reverse proxy
34
+ clients: [
35
+ {
36
+ client_id: 'partner',
37
+ client_secret: process.env.PARTNER_SECRET,
38
+ client_name: 'Partner App',
39
+ redirect_uris: ['https://partner.example.com/callback'],
40
+ },
41
+ ],
42
+ });
43
+
44
+ mountOIDCProviderExpress(app, provider); // before express.json()
45
+ ```
46
+
47
+ ## NestJS
48
+
49
+ ```ts
50
+ // app.module.ts
51
+ imports: [AuthModule.forRoot(authConfig), OIDCProviderModule.forRoot(oidcConfig)]
52
+
53
+ // main.ts — after create(), before the body parsers and setGlobalPrefix
54
+ mountOIDCProviderNest(app, app.get(NAUTH_OIDC_PROVIDER));
55
+ ```
56
+
57
+ `OIDCProviderModule.forRoot()` also registers the interaction controller your consent
58
+ screen talks to, at `oidc/interaction/:uid` (under any global prefix). Move it or take
59
+ it over:
60
+
61
+ ```ts
62
+ OIDCProviderModule.forRoot({
63
+ ...oidcConfig,
64
+ interaction: { path: 'identity/interaction' }, // or { enabled: false } to write your own
65
+ });
66
+ ```
67
+
68
+ Those routes are ordinary nauth routes — full guard chain, full request context —
69
+ unlike the provider's own endpoints, which own raw HTTP under `pathPrefix`. Writing
70
+ your own means injecting `NAUTH_OIDC_BRIDGE` and calling it; start from
71
+ `createOIDCInteractionController`, and note that it applies `@UseGuards(AuthGuard)` at
72
+ the class level *and* `@Public()` on every route. That combination is load-bearing:
73
+ `AuthGuard` is not global in this toolkit, so without it the session gate reports
74
+ `no_session` for everyone, and `@Public()` is what makes it attach a user when there is
75
+ one without rejecting the anonymous caller you have to answer.
76
+
77
+ ## The consent screen
78
+
79
+ The frontend SDK drives all four routes, so there is no hand-written HTTP in your app:
80
+
81
+ ```ts
82
+ const state = await client.oidc.getInteraction(uid);
83
+
84
+ if (state.gate === 'login_required') {
85
+ await client.oidc.setPendingInteraction(uid); // survives the whole challenge chain
86
+ router.navigate(['/login']);
87
+ } else if (state.prompt === 'login') {
88
+ window.location.assign((await client.oidc.completeLogin(uid)).redirectTo);
89
+ } else {
90
+ // render state.client and state.missingScopes, then:
91
+ window.location.assign((await client.oidc.approve(uid)).redirectTo);
92
+ }
93
+ ```
94
+
95
+ Angular apps get `auth.oidc` on `AuthService` and an optional `oidcReturnGuard()` for
96
+ routes a freshly logged-in user lands on. See `examples/demo-nestjs` for the backend
97
+ wired up and `examples/demo-angular` for the interaction page.
98
+
99
+ ## Errors the frontend has to act on
100
+
101
+ Bridge failures are `NAuthException`s, so `NAuthHttpExceptionFilter` maps them:
102
+
103
+ | Code | Status | Meaning |
104
+ |---|---|---|
105
+ | `OIDC_INTERACTION_NOT_FOUND` | 404 | Expired or already resolved. Start again from the client. |
106
+ | `OIDC_LOGIN_REQUIRED` | 401 | Recoverable. `details.uid` says what to come back to. |
107
+
108
+ A session that lapses while the consent screen sits open is the common case, and it
109
+ surfaces as `OIDC_LOGIN_REQUIRED` on the confirm call — re-stash `details.uid`, send the
110
+ user through login, and resume.
111
+
112
+ A **disabled or locked account is not an error.** The bridge resolves the interaction
113
+ with `access_denied` and returns an ordinary `redirectTo`, so the relying party gets a
114
+ protocol error rather than the user getting a dead browser tab. Follow the redirect as
115
+ you would any other.
116
+
117
+ ## What lands in the audit trail
118
+
119
+ When audit logs are enabled, the bridge records who was released to which application —
120
+ something the ordinary `LOGIN_SUCCESS` cannot say, because the authorization request is
121
+ still parked when the user types their password.
122
+
123
+ | Event | When |
124
+ |---|---|
125
+ | `OIDC_LOGIN_COMPLETED` | A completed login was released to a relying party |
126
+ | `OIDC_CONSENT_GRANTED` | The user approved the request |
127
+ | `OIDC_CONSENT_DENIED` | The user refused it |
128
+ | `OIDC_ACCESS_DENIED` | The account may not be vouched for |
129
+
130
+ Each carries `authMethod: 'oidc'` and a metadata object with `clientId`,
131
+ `interactionUid`, `requestedScopes` and (on a grant) `grantedScopes`. IP address,
132
+ geolocation, device and user agent are captured automatically, because these are
133
+ ordinary nauth-toolkit routes.
134
+
135
+ **Scope:** this covers the login and consent decisions. Token issuance, refresh and
136
+ introspection happen on the provider's own endpoints, outside the request context, and
137
+ are **not** recorded.
138
+
139
+ ## Two things that will bite you
140
+
141
+ **The issuer must be an origin with no path.** `oidc-provider` builds every endpoint URL as `new URL(absolutePath, issuer)`, so a path on the issuer is silently discarded — `new URL('/auth', 'https://host/oidc')` is `https://host/auth`. Configure `issuer: 'https://host'` and namespace the endpoints with `pathPrefix` instead, which is what this package does for you. Discovery then lands at `/.well-known/openid-configuration`, exactly where OpenID Connect Discovery expects it.
142
+
143
+ **Mount before your body parsers.** `oidc-provider` reads the raw request stream for `POST /token`. It does fall back to a pre-parsed `req.body`, so it works either way, but mounting first avoids a startup warning and keeps its own request size limit.
144
+
145
+ ## What this package hardens by default
146
+
147
+ | | Upstream default | Here |
148
+ |---|---|---|
149
+ | Response types | `code`, `id_token`, `code id_token`, `none` | **`code` only** — no implicit or hybrid |
150
+ | PKCE | required for public clients | **required for every client** (RFC 9700) |
151
+ | Introspection / revocation | disabled | **enabled**, and a client may only reach **its own** tokens |
152
+ | Refresh tokens | require the `offline_access` scope | issued whenever the client registers the grant |
153
+ | Artifact lifetimes | warn-on-default | set explicitly |
154
+ | Built-in dev login screens | enabled | **disabled** — nauth owns login |
155
+
156
+ ## Storage
157
+
158
+ Every provider artifact lives in nauth's existing `StorageAdapter`. **No new tables and no migrations.** Use Redis in production; the database adapter is fine for low traffic, and the in-memory one is single-instance only.
@@ -0,0 +1,12 @@
1
+ export { OIDCProviderModule } from './oidc-provider.module';
2
+ export type { OIDCProviderModuleOptions, OIDCInteractionRouteOptions } from './oidc-provider.module';
3
+ export { NAUTH_OIDC_PROVIDER, NAUTH_OIDC_BRIDGE, NAUTH_OIDC_SESSIONS } from './tokens';
4
+ export { createOIDCInteractionController, DEFAULT_INTERACTION_PATH } from './oidc-interaction.controller';
5
+ export type { OIDCConsentBody } from './oidc-interaction.controller';
6
+ export { mountOIDCProviderNest } from './mount';
7
+ export { OIDCInteractionBridge } from '../src/interaction-bridge';
8
+ export type { InteractionStateDTO, InteractionRedirectDTO } from '../src/interaction-bridge';
9
+ export { OIDCSessionTerminator } from '../src/session-termination';
10
+ export { createOIDCRateLimiter } from '../src/rate-limit';
11
+ export type { OIDCRateLimitConfig } from '../src/rate-limit';
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,23 @@
1
+ "use strict";
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;
4
+ var oidc_provider_module_1 = require("./oidc-provider.module");
5
+ Object.defineProperty(exports, "OIDCProviderModule", { enumerable: true, get: function () { return oidc_provider_module_1.OIDCProviderModule; } });
6
+ var tokens_1 = require("./tokens");
7
+ Object.defineProperty(exports, "NAUTH_OIDC_PROVIDER", { enumerable: true, get: function () { return tokens_1.NAUTH_OIDC_PROVIDER; } });
8
+ Object.defineProperty(exports, "NAUTH_OIDC_BRIDGE", { enumerable: true, get: function () { return tokens_1.NAUTH_OIDC_BRIDGE; } });
9
+ Object.defineProperty(exports, "NAUTH_OIDC_SESSIONS", { enumerable: true, get: function () { return tokens_1.NAUTH_OIDC_SESSIONS; } });
10
+ var oidc_interaction_controller_1 = require("./oidc-interaction.controller");
11
+ Object.defineProperty(exports, "createOIDCInteractionController", { enumerable: true, get: function () { return oidc_interaction_controller_1.createOIDCInteractionController; } });
12
+ Object.defineProperty(exports, "DEFAULT_INTERACTION_PATH", { enumerable: true, get: function () { return oidc_interaction_controller_1.DEFAULT_INTERACTION_PATH; } });
13
+ var mount_1 = require("./mount");
14
+ Object.defineProperty(exports, "mountOIDCProviderNest", { enumerable: true, get: function () { return mount_1.mountOIDCProviderNest; } });
15
+ // Re-exported so a consumer's controller can type the bridge it injects without
16
+ // reaching into the root entry point as well.
17
+ var interaction_bridge_1 = require("../src/interaction-bridge");
18
+ Object.defineProperty(exports, "OIDCInteractionBridge", { enumerable: true, get: function () { return interaction_bridge_1.OIDCInteractionBridge; } });
19
+ var session_termination_1 = require("../src/session-termination");
20
+ Object.defineProperty(exports, "OIDCSessionTerminator", { enumerable: true, get: function () { return session_termination_1.OIDCSessionTerminator; } });
21
+ var rate_limit_1 = require("../src/rate-limit");
22
+ Object.defineProperty(exports, "createOIDCRateLimiter", { enumerable: true, get: function () { return rate_limit_1.createOIDCRateLimiter; } });
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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"}
@@ -0,0 +1,38 @@
1
+ import type Provider from 'oidc-provider';
2
+ /** The slice of `INestApplication` this helper needs. */
3
+ interface NestAppLike {
4
+ getHttpAdapter(): {
5
+ getInstance(): unknown;
6
+ };
7
+ }
8
+ /**
9
+ * Attach an OpenID Connect provider to a NestJS application.
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.
17
+ *
18
+ * Because the mount is on the platform instance, `setGlobalPrefix('api')` does not
19
+ * apply to it: the provider's endpoints sit at the origin root exactly as its
20
+ * discovery document advertises them.
21
+ *
22
+ * @param app - The Nest application
23
+ * @param provider - A configured provider
24
+ * @param options - The path prefix its routes were configured with
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * const app = await NestFactory.create(AppModule, new ExpressAdapter());
29
+ * mountOIDCProviderNest(app, app.get(NAUTH_OIDC_PROVIDER));
30
+ * app.use(cookieParser());
31
+ * app.setGlobalPrefix('api');
32
+ * ```
33
+ */
34
+ export declare function mountOIDCProviderNest(app: NestAppLike, provider: Provider, options?: {
35
+ pathPrefix?: string;
36
+ }): void;
37
+ export {};
38
+ //# sourceMappingURL=mount.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mountOIDCProviderNest = mountOIDCProviderNest;
4
+ const express_1 = require("../src/mount/express");
5
+ /**
6
+ * Attach an OpenID Connect provider to a NestJS application.
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.
14
+ *
15
+ * Because the mount is on the platform instance, `setGlobalPrefix('api')` does not
16
+ * apply to it: the provider's endpoints sit at the origin root exactly as its
17
+ * discovery document advertises them.
18
+ *
19
+ * @param app - The Nest application
20
+ * @param provider - A configured provider
21
+ * @param options - The path prefix its routes were configured with
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * const app = await NestFactory.create(AppModule, new ExpressAdapter());
26
+ * mountOIDCProviderNest(app, app.get(NAUTH_OIDC_PROVIDER));
27
+ * app.use(cookieParser());
28
+ * app.setGlobalPrefix('api');
29
+ * ```
30
+ */
31
+ function mountOIDCProviderNest(app, provider, options = {}) {
32
+ const instance = app.getHttpAdapter().getInstance();
33
+ (0, express_1.mountOIDCProviderExpress)(instance, provider, options);
34
+ }
35
+ //# sourceMappingURL=mount.js.map
@@ -0,0 +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"}
@@ -0,0 +1,40 @@
1
+ import { Type } from '@nestjs/common';
2
+ /** The path the interaction routes are served under when nothing else is asked for. */
3
+ export declare const DEFAULT_INTERACTION_PATH = "oidc/interaction";
4
+ /** What the consent screen sends when the user decides. */
5
+ export interface OIDCConsentBody {
6
+ /** Whether the user approved. Anything but an explicit `false` is an approval. */
7
+ approve?: boolean;
8
+ /** A narrowed set of scopes to grant. Omit to grant everything that was asked for. */
9
+ scopes?: string[];
10
+ }
11
+ /**
12
+ * Build the controller that bridges the OpenID Connect provider and nauth's login.
13
+ *
14
+ * These four routes are the same in every deployment, so the package ships them rather
15
+ * than leaving each consumer to write them. They are ordinary nauth routes — full
16
+ * request context, full guard chain — unlike the provider's own endpoints, which own
17
+ * raw HTTP under the provider's own path prefix. The split is deliberate: the
18
+ * provider needs no nauth context, and these need all of it.
19
+ *
20
+ * Every route answers with a `redirectTo` as JSON rather than issuing a 302, so a
21
+ * single-page app can drive the flow with `fetch` and navigate itself.
22
+ *
23
+ * A factory rather than an exported class because Nest's `@Controller` decorator is
24
+ * static: taking the path as an argument is the only way to let a consumer mount these
25
+ * somewhere other than the default. `OIDCProviderModule.forRoot()` calls this for you;
26
+ * call it directly only if you are registering the controller in your own module.
27
+ *
28
+ * @param path - Path to serve the routes under, relative to any global prefix
29
+ * @returns A Nest controller class, ready to list in a module's `controllers`
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * @Module({
34
+ * controllers: [createOIDCInteractionController('identity/interaction')],
35
+ * })
36
+ * export class MyOIDCModule {}
37
+ * ```
38
+ */
39
+ export declare function createOIDCInteractionController(path?: string): Type<unknown>;
40
+ //# sourceMappingURL=oidc-interaction.controller.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oidc-interaction.controller.d.ts","sourceRoot":"","sources":["../../nestjs/oidc-interaction.controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiD,IAAI,EAAa,MAAM,gBAAgB,CAAC;AAKhG,uFAAuF;AACvF,eAAO,MAAM,wBAAwB,qBAAqB,CAAC;AAE3D,2DAA2D;AAC3D,MAAM,WAAW,eAAe;IAC9B,kFAAkF;IAClF,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,sFAAsF;IACtF,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,+BAA+B,CAAC,IAAI,GAAE,MAAiC,GAAG,IAAI,CAAC,OAAO,CAAC,CA+EtG"}
@@ -0,0 +1,157 @@
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.DEFAULT_INTERACTION_PATH = void 0;
16
+ exports.createOIDCInteractionController = createOIDCInteractionController;
17
+ const common_1 = require("@nestjs/common");
18
+ const nestjs_1 = require("@nauth-toolkit/nestjs");
19
+ const tokens_1 = require("./tokens");
20
+ /** The path the interaction routes are served under when nothing else is asked for. */
21
+ exports.DEFAULT_INTERACTION_PATH = 'oidc/interaction';
22
+ /**
23
+ * Build the controller that bridges the OpenID Connect provider and nauth's login.
24
+ *
25
+ * These four routes are the same in every deployment, so the package ships them rather
26
+ * than leaving each consumer to write them. They are ordinary nauth routes — full
27
+ * request context, full guard chain — unlike the provider's own endpoints, which own
28
+ * raw HTTP under the provider's own path prefix. The split is deliberate: the
29
+ * provider needs no nauth context, and these need all of it.
30
+ *
31
+ * Every route answers with a `redirectTo` as JSON rather than issuing a 302, so a
32
+ * single-page app can drive the flow with `fetch` and navigate itself.
33
+ *
34
+ * A factory rather than an exported class because Nest's `@Controller` decorator is
35
+ * static: taking the path as an argument is the only way to let a consumer mount these
36
+ * somewhere other than the default. `OIDCProviderModule.forRoot()` calls this for you;
37
+ * call it directly only if you are registering the controller in your own module.
38
+ *
39
+ * @param path - Path to serve the routes under, relative to any global prefix
40
+ * @returns A Nest controller class, ready to list in a module's `controllers`
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * @Module({
45
+ * controllers: [createOIDCInteractionController('identity/interaction')],
46
+ * })
47
+ * export class MyOIDCModule {}
48
+ * ```
49
+ */
50
+ function createOIDCInteractionController(path = exports.DEFAULT_INTERACTION_PATH) {
51
+ // AuthGuard is applied at the controller level, and every route is also @Public().
52
+ //
53
+ // That combination is deliberate: in this toolkit AuthGuard is not a global guard, so
54
+ // without it `CURRENT_USER` is never populated and the session gate would report
55
+ // `no_session` for everyone, forever. @Public() then makes the guard *optional* — it
56
+ // attaches the user when a valid session is present and never rejects — which is
57
+ // exactly what these routes need, since an anonymous caller is the case that has to
58
+ // work in order to send someone to the login page.
59
+ let OIDCInteractionController = class OIDCInteractionController {
60
+ bridge;
61
+ constructor(bridge) {
62
+ this.bridge = bridge;
63
+ }
64
+ /**
65
+ * Describe a pending interaction so the frontend can decide what to render.
66
+ *
67
+ * Public on purpose: a signed-out caller is exactly the case the frontend needs an
68
+ * answer for.
69
+ *
70
+ * @param req - The incoming request
71
+ * @param res - The outgoing response, in passthrough mode
72
+ * @returns What the interaction needs, and nauth's verdict on the caller's session
73
+ */
74
+ async state(req, res) {
75
+ return this.bridge.getState(req, res);
76
+ }
77
+ /**
78
+ * Complete the login step for the currently authenticated user.
79
+ *
80
+ * @param req - The incoming request
81
+ * @param res - The outgoing response, in passthrough mode
82
+ * @returns Where to send the browser to resume the authorization request
83
+ */
84
+ async login(req, res) {
85
+ return this.bridge.completeLogin(req, res);
86
+ }
87
+ /**
88
+ * Record the user's consent decision.
89
+ *
90
+ * @param body - Whether the user approved, and optionally a narrowed scope set
91
+ * @param req - The incoming request
92
+ * @param res - The outgoing response, in passthrough mode
93
+ * @returns Where to send the browser next
94
+ */
95
+ async confirm(body, req, res) {
96
+ return this.bridge.completeConsent(req, res, {
97
+ approve: body?.approve !== false,
98
+ scopes: body?.scopes,
99
+ });
100
+ }
101
+ /**
102
+ * Abandon a pending interaction, so the relying party gets a clean protocol error.
103
+ *
104
+ * @param req - The incoming request
105
+ * @param res - The outgoing response, in passthrough mode
106
+ * @returns Where to send the browser
107
+ */
108
+ async abort(req, res) {
109
+ return this.bridge.abort(req, res);
110
+ }
111
+ };
112
+ __decorate([
113
+ (0, nestjs_1.Public)(),
114
+ (0, common_1.Get)(':uid'),
115
+ __param(0, (0, common_1.Req)()),
116
+ __param(1, (0, common_1.Res)({ passthrough: true })),
117
+ __metadata("design:type", Function),
118
+ __metadata("design:paramtypes", [Object, Object]),
119
+ __metadata("design:returntype", Promise)
120
+ ], OIDCInteractionController.prototype, "state", null);
121
+ __decorate([
122
+ (0, nestjs_1.Public)(),
123
+ (0, common_1.Post)(':uid/login'),
124
+ __param(0, (0, common_1.Req)()),
125
+ __param(1, (0, common_1.Res)({ passthrough: true })),
126
+ __metadata("design:type", Function),
127
+ __metadata("design:paramtypes", [Object, Object]),
128
+ __metadata("design:returntype", Promise)
129
+ ], OIDCInteractionController.prototype, "login", null);
130
+ __decorate([
131
+ (0, nestjs_1.Public)(),
132
+ (0, common_1.Post)(':uid/confirm'),
133
+ __param(0, (0, common_1.Body)()),
134
+ __param(1, (0, common_1.Req)()),
135
+ __param(2, (0, common_1.Res)({ passthrough: true })),
136
+ __metadata("design:type", Function),
137
+ __metadata("design:paramtypes", [Object, Object, Object]),
138
+ __metadata("design:returntype", Promise)
139
+ ], OIDCInteractionController.prototype, "confirm", null);
140
+ __decorate([
141
+ (0, nestjs_1.Public)(),
142
+ (0, common_1.Post)(':uid/abort'),
143
+ __param(0, (0, common_1.Req)()),
144
+ __param(1, (0, common_1.Res)({ passthrough: true })),
145
+ __metadata("design:type", Function),
146
+ __metadata("design:paramtypes", [Object, Object]),
147
+ __metadata("design:returntype", Promise)
148
+ ], OIDCInteractionController.prototype, "abort", null);
149
+ OIDCInteractionController = __decorate([
150
+ (0, common_1.UseGuards)(nestjs_1.AuthGuard),
151
+ (0, common_1.Controller)(path),
152
+ __param(0, (0, common_1.Inject)(tokens_1.NAUTH_OIDC_BRIDGE)),
153
+ __metadata("design:paramtypes", [Function])
154
+ ], OIDCInteractionController);
155
+ return OIDCInteractionController;
156
+ }
157
+ //# sourceMappingURL=oidc-interaction.controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oidc-interaction.controller.js","sourceRoot":"","sources":["../../nestjs/oidc-interaction.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AA4CA,0EA+EC;AA3HD,2CAAgG;AAChG,kDAA0D;AAC1D,qCAA6C;AAG7C,uFAAuF;AAC1E,QAAA,wBAAwB,GAAG,kBAAkB,CAAC;AAU3D;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,SAAgB,+BAA+B,CAAC,OAAe,gCAAwB;IACrF,mFAAmF;IACnF,EAAE;IACF,sFAAsF;IACtF,iFAAiF;IACjF,qFAAqF;IACrF,iFAAiF;IACjF,oFAAoF;IACpF,mDAAmD;IACnD,IAEM,yBAAyB,GAF/B,MAEM,yBAAyB;QAC2B;QAAxD,YAAwD,MAA6B;YAA7B,WAAM,GAAN,MAAM,CAAuB;QAAG,CAAC;QAEzF;;;;;;;;;WASG;QAGG,AAAN,KAAK,CAAC,KAAK,CAAQ,GAAY,EAA8B,GAAY;YACvE,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACxC,CAAC;QAED;;;;;;WAMG;QAGG,AAAN,KAAK,CAAC,KAAK,CAAQ,GAAY,EAA8B,GAAY;YACvE,OAAO,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAC7C,CAAC;QAED;;;;;;;WAOG;QAGG,AAAN,KAAK,CAAC,OAAO,CACH,IAAqB,EACtB,GAAY,EACS,GAAY;YAExC,OAAO,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,GAAG,EAAE,GAAG,EAAE;gBAC3C,OAAO,EAAE,IAAI,EAAE,OAAO,KAAK,KAAK;gBAChC,MAAM,EAAE,IAAI,EAAE,MAAM;aACrB,CAAC,CAAC;QACL,CAAC;QAED;;;;;;WAMG;QAGG,AAAN,KAAK,CAAC,KAAK,CAAQ,GAAY,EAA8B,GAAY;YACvE,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACrC,CAAC;KACF,CAAA;IAlDO;QAFL,IAAA,eAAM,GAAE;QACR,IAAA,YAAG,EAAC,MAAM,CAAC;QACC,WAAA,IAAA,YAAG,GAAE,CAAA;QAAgB,WAAA,IAAA,YAAG,EAAC,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAA;;;;0DAE3D;IAWK;QAFL,IAAA,eAAM,GAAE;QACR,IAAA,aAAI,EAAC,YAAY,CAAC;QACN,WAAA,IAAA,YAAG,GAAE,CAAA;QAAgB,WAAA,IAAA,YAAG,EAAC,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAA;;;;0DAE3D;IAYK;QAFL,IAAA,eAAM,GAAE;QACR,IAAA,aAAI,EAAC,cAAc,CAAC;QAElB,WAAA,IAAA,aAAI,GAAE,CAAA;QACN,WAAA,IAAA,YAAG,GAAE,CAAA;QACL,WAAA,IAAA,YAAG,EAAC,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAA;;;;4DAM5B;IAWK;QAFL,IAAA,eAAM,GAAE;QACR,IAAA,aAAI,EAAC,YAAY,CAAC;QACN,WAAA,IAAA,YAAG,GAAE,CAAA;QAAgB,WAAA,IAAA,YAAG,EAAC,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAA;;;;0DAE3D;IAhEG,yBAAyB;QAF9B,IAAA,kBAAS,EAAC,kBAAS,CAAC;QACpB,IAAA,mBAAU,EAAC,IAAI,CAAC;QAEF,WAAA,IAAA,eAAM,EAAC,0BAAiB,CAAC,CAAA;;OADlC,yBAAyB,CAiE9B;IAED,OAAO,yBAAyB,CAAC;AACnC,CAAC"}
@@ -0,0 +1,70 @@
1
+ import { DynamicModule } from '@nestjs/common';
2
+ import type { NAuthOIDCOptions } from '../src/config.types';
3
+ import { NAUTH_OIDC_BRIDGE, NAUTH_OIDC_PROVIDER, NAUTH_OIDC_SESSIONS } from './tokens';
4
+ export { NAUTH_OIDC_BRIDGE, NAUTH_OIDC_PROVIDER, NAUTH_OIDC_SESSIONS };
5
+ /**
6
+ * How the module registers the interaction routes the consent screen talks to.
7
+ */
8
+ export interface OIDCInteractionRouteOptions {
9
+ /**
10
+ * Register the shipped interaction controller.
11
+ *
12
+ * Turn this off to write your own — the bridge stays exported either way, so a
13
+ * hand-written controller only has to inject `NAUTH_OIDC_BRIDGE` and call it.
14
+ *
15
+ * @default true
16
+ */
17
+ enabled?: boolean;
18
+ /**
19
+ * Path the interaction routes are served under, relative to any global prefix.
20
+ *
21
+ * With Nest's `setGlobalPrefix('api')` the default lands the routes at
22
+ * `/api/oidc/interaction/:uid`. Whatever you choose here has to match the frontend
23
+ * SDK's `oidc.basePath`.
24
+ *
25
+ * @default 'oidc/interaction'
26
+ */
27
+ path?: string;
28
+ }
29
+ /**
30
+ * Everything the module needs that is not already available from `AuthModule`.
31
+ *
32
+ * Storage and the user repository are resolved from `AuthModule`'s exports, so they
33
+ * are deliberately absent here.
34
+ */
35
+ export type OIDCProviderModuleOptions = Omit<NAuthOIDCOptions, 'storage' | 'userRepository'> & {
36
+ /** How the interaction routes are registered. */
37
+ interaction?: OIDCInteractionRouteOptions;
38
+ };
39
+ /**
40
+ * Registers an OpenID Connect provider alongside `AuthModule`.
41
+ *
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.
47
+ *
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.
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * // app.module.ts
55
+ * 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
+ * ```
60
+ */
61
+ export declare class OIDCProviderModule {
62
+ /**
63
+ * Configure the provider.
64
+ *
65
+ * @param options - Issuer, interaction URL, cookie keys, clients and interaction routing
66
+ * @returns A dynamic module exporting the provider and its interaction bridge
67
+ */
68
+ static forRoot(options: OIDCProviderModuleOptions): DynamicModule;
69
+ }
70
+ //# sourceMappingURL=oidc-provider.module.d.ts.map
@@ -0,0 +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"}