@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.
- package/LICENSE +21 -0
- package/README.md +158 -0
- package/dist/nestjs/index.d.ts +12 -0
- package/dist/nestjs/index.d.ts.map +1 -0
- package/dist/nestjs/index.js +23 -0
- package/dist/nestjs/index.js.map +1 -0
- package/dist/nestjs/mount.d.ts +38 -0
- package/dist/nestjs/mount.d.ts.map +1 -0
- package/dist/nestjs/mount.js +35 -0
- package/dist/nestjs/mount.js.map +1 -0
- package/dist/nestjs/oidc-interaction.controller.d.ts +40 -0
- package/dist/nestjs/oidc-interaction.controller.d.ts.map +1 -0
- package/dist/nestjs/oidc-interaction.controller.js +157 -0
- package/dist/nestjs/oidc-interaction.controller.js.map +1 -0
- package/dist/nestjs/oidc-provider.module.d.ts +70 -0
- package/dist/nestjs/oidc-provider.module.d.ts.map +1 -0
- package/dist/nestjs/oidc-provider.module.js +84 -0
- package/dist/nestjs/oidc-provider.module.js.map +1 -0
- package/dist/nestjs/tokens.d.ts +13 -0
- package/dist/nestjs/tokens.d.ts.map +1 -0
- package/dist/nestjs/tokens.js +16 -0
- package/dist/nestjs/tokens.js.map +1 -0
- package/dist/src/config.types.d.ts +102 -0
- package/dist/src/config.types.d.ts.map +1 -0
- package/dist/src/config.types.js +3 -0
- package/dist/src/config.types.js.map +1 -0
- package/dist/src/create-provider.d.ts +47 -0
- package/dist/src/create-provider.d.ts.map +1 -0
- package/dist/src/create-provider.js +159 -0
- package/dist/src/create-provider.js.map +1 -0
- package/dist/src/find-account.d.ts +33 -0
- package/dist/src/find-account.d.ts.map +1 -0
- package/dist/src/find-account.js +69 -0
- package/dist/src/find-account.js.map +1 -0
- package/dist/src/index.d.ts +41 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +51 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/interaction-bridge.d.ts +147 -0
- package/dist/src/interaction-bridge.d.ts.map +1 -0
- package/dist/src/interaction-bridge.js +283 -0
- package/dist/src/interaction-bridge.js.map +1 -0
- package/dist/src/mount/express.d.ts +54 -0
- package/dist/src/mount/express.d.ts.map +1 -0
- package/dist/src/mount/express.js +56 -0
- package/dist/src/mount/express.js.map +1 -0
- package/dist/src/rate-limit.d.ts +61 -0
- package/dist/src/rate-limit.d.ts.map +1 -0
- package/dist/src/rate-limit.js +93 -0
- package/dist/src/rate-limit.js.map +1 -0
- package/dist/src/raw-http.d.ts +25 -0
- package/dist/src/raw-http.d.ts.map +1 -0
- package/dist/src/raw-http.js +33 -0
- package/dist/src/raw-http.js.map +1 -0
- package/dist/src/session-termination.d.ts +60 -0
- package/dist/src/session-termination.d.ts.map +1 -0
- package/dist/src/session-termination.js +70 -0
- package/dist/src/session-termination.js.map +1 -0
- package/dist/src/storage.adapter.d.ts +99 -0
- package/dist/src/storage.adapter.d.ts.map +1 -0
- package/dist/src/storage.adapter.js +197 -0
- package/dist/src/storage.adapter.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +95 -0
|
@@ -0,0 +1,84 @@
|
|
|
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 OIDCProviderModule_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.OIDCProviderModule = exports.NAUTH_OIDC_SESSIONS = exports.NAUTH_OIDC_PROVIDER = exports.NAUTH_OIDC_BRIDGE = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const internal_1 = require("@nauth-toolkit/core/internal");
|
|
13
|
+
const create_provider_1 = require("../src/create-provider");
|
|
14
|
+
const interaction_bridge_1 = require("../src/interaction-bridge");
|
|
15
|
+
const session_termination_1 = require("../src/session-termination");
|
|
16
|
+
const tokens_1 = require("./tokens");
|
|
17
|
+
Object.defineProperty(exports, "NAUTH_OIDC_BRIDGE", { enumerable: true, get: function () { return tokens_1.NAUTH_OIDC_BRIDGE; } });
|
|
18
|
+
Object.defineProperty(exports, "NAUTH_OIDC_PROVIDER", { enumerable: true, get: function () { return tokens_1.NAUTH_OIDC_PROVIDER; } });
|
|
19
|
+
Object.defineProperty(exports, "NAUTH_OIDC_SESSIONS", { enumerable: true, get: function () { return tokens_1.NAUTH_OIDC_SESSIONS; } });
|
|
20
|
+
const oidc_interaction_controller_1 = require("./oidc-interaction.controller");
|
|
21
|
+
/**
|
|
22
|
+
* Registers an OpenID Connect provider alongside `AuthModule`.
|
|
23
|
+
*
|
|
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.
|
|
29
|
+
*
|
|
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.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* // app.module.ts
|
|
37
|
+
* 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
|
+
*/
|
|
43
|
+
let OIDCProviderModule = OIDCProviderModule_1 = class OIDCProviderModule {
|
|
44
|
+
/**
|
|
45
|
+
* Configure the provider.
|
|
46
|
+
*
|
|
47
|
+
* @param options - Issuer, interaction URL, cookie keys, clients and interaction routing
|
|
48
|
+
* @returns A dynamic module exporting the provider and its interaction bridge
|
|
49
|
+
*/
|
|
50
|
+
static forRoot(options) {
|
|
51
|
+
const { interaction, ...providerOptions } = options;
|
|
52
|
+
const providerFactory = {
|
|
53
|
+
provide: tokens_1.NAUTH_OIDC_PROVIDER,
|
|
54
|
+
useFactory: async (storage, userRepository) => (0, create_provider_1.createNAuthOIDCProvider)({ ...providerOptions, storage, userRepository }),
|
|
55
|
+
inject: ['STORAGE_ADAPTER', 'UserRepository'],
|
|
56
|
+
};
|
|
57
|
+
const bridgeFactory = {
|
|
58
|
+
provide: tokens_1.NAUTH_OIDC_BRIDGE,
|
|
59
|
+
useFactory: (provider, gate, audit) => new interaction_bridge_1.OIDCInteractionBridge(provider, gate, audit),
|
|
60
|
+
// The audit service is optional: `AuthModule` only exports it when audit logs are
|
|
61
|
+
// enabled, and the bridge simply records nothing when it is absent.
|
|
62
|
+
inject: [tokens_1.NAUTH_OIDC_PROVIDER, internal_1.IdpSessionGate, { token: internal_1.AuthAuditService, optional: true }],
|
|
63
|
+
};
|
|
64
|
+
const terminatorFactory = {
|
|
65
|
+
provide: tokens_1.NAUTH_OIDC_SESSIONS,
|
|
66
|
+
useFactory: (storage) => new session_termination_1.OIDCSessionTerminator(storage),
|
|
67
|
+
inject: ['STORAGE_ADAPTER'],
|
|
68
|
+
};
|
|
69
|
+
const controllers = interaction?.enabled === false
|
|
70
|
+
? []
|
|
71
|
+
: [(0, oidc_interaction_controller_1.createOIDCInteractionController)(interaction?.path ?? oidc_interaction_controller_1.DEFAULT_INTERACTION_PATH)];
|
|
72
|
+
return {
|
|
73
|
+
module: OIDCProviderModule_1,
|
|
74
|
+
controllers,
|
|
75
|
+
providers: [providerFactory, bridgeFactory, terminatorFactory],
|
|
76
|
+
exports: [tokens_1.NAUTH_OIDC_PROVIDER, tokens_1.NAUTH_OIDC_BRIDGE, tokens_1.NAUTH_OIDC_SESSIONS],
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
exports.OIDCProviderModule = OIDCProviderModule;
|
|
81
|
+
exports.OIDCProviderModule = OIDCProviderModule = OIDCProviderModule_1 = __decorate([
|
|
82
|
+
(0, common_1.Module)({})
|
|
83
|
+
], OIDCProviderModule);
|
|
84
|
+
//# sourceMappingURL=oidc-provider.module.js.map
|
|
@@ -0,0 +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,gBAAgB,CAAC;SAC9C,CAAC;QAEF,MAAM,aAAa,GAAiB;YAClC,OAAO,EAAE,0BAAiB;YAC1B,UAAU,EAAE,CAAC,QAAkB,EAAE,IAAoB,EAAE,KAAwB,EAAyB,EAAE,CACxG,IAAI,0CAAqB,CAAC,QAAQ,EAAE,IAAI,EAAE,KAAK,CAAC;YAClD,kFAAkF;YAClF,oEAAoE;YACpE,MAAM,EAAE,CAAC,4BAAmB,EAAE,yBAAc,EAAE,EAAE,KAAK,EAAE,2BAAgB,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;SAC3F,CAAC;QAEF,MAAM,iBAAiB,GAAiB;YACtC,OAAO,EAAE,4BAAmB;YAC5B,UAAU,EAAE,CAAC,OAAuB,EAAyB,EAAE,CAAC,IAAI,2CAAqB,CAAC,OAAO,CAAC;YAClG,MAAM,EAAE,CAAC,iBAAiB,CAAC;SAC5B,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,OAAO;YACL,MAAM,EAAE,oBAAkB;YAC1B,WAAW;YACX,SAAS,EAAE,CAAC,eAAe,EAAE,aAAa,EAAE,iBAAiB,CAAC;YAC9D,OAAO,EAAE,CAAC,4BAAmB,EAAE,0BAAiB,EAAE,4BAAmB,CAAC;SACvE,CAAC;IACJ,CAAC;CACF,CAAA;AA5CY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,kBAAkB,CA4C9B"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Injection tokens for the OpenID Connect provider module.
|
|
3
|
+
*
|
|
4
|
+
* Kept in their own file so a controller can inject the bridge without importing the
|
|
5
|
+
* module that registers the controller.
|
|
6
|
+
*/
|
|
7
|
+
/** Injection token for the configured `oidc-provider` instance. */
|
|
8
|
+
export declare const NAUTH_OIDC_PROVIDER = "NAUTH_OIDC_PROVIDER";
|
|
9
|
+
/** Injection token for the interaction bridge. */
|
|
10
|
+
export declare const NAUTH_OIDC_BRIDGE = "NAUTH_OIDC_BRIDGE";
|
|
11
|
+
/** Injection token for the single-logout helper. */
|
|
12
|
+
export declare const NAUTH_OIDC_SESSIONS = "NAUTH_OIDC_SESSIONS";
|
|
13
|
+
//# sourceMappingURL=tokens.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../../nestjs/tokens.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,mEAAmE;AACnE,eAAO,MAAM,mBAAmB,wBAAwB,CAAC;AAEzD,kDAAkD;AAClD,eAAO,MAAM,iBAAiB,sBAAsB,CAAC;AAErD,oDAAoD;AACpD,eAAO,MAAM,mBAAmB,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Injection tokens for the OpenID Connect provider module.
|
|
4
|
+
*
|
|
5
|
+
* Kept in their own file so a controller can inject the bridge without importing the
|
|
6
|
+
* module that registers the controller.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.NAUTH_OIDC_SESSIONS = exports.NAUTH_OIDC_BRIDGE = exports.NAUTH_OIDC_PROVIDER = void 0;
|
|
10
|
+
/** Injection token for the configured `oidc-provider` instance. */
|
|
11
|
+
exports.NAUTH_OIDC_PROVIDER = 'NAUTH_OIDC_PROVIDER';
|
|
12
|
+
/** Injection token for the interaction bridge. */
|
|
13
|
+
exports.NAUTH_OIDC_BRIDGE = 'NAUTH_OIDC_BRIDGE';
|
|
14
|
+
/** Injection token for the single-logout helper. */
|
|
15
|
+
exports.NAUTH_OIDC_SESSIONS = 'NAUTH_OIDC_SESSIONS';
|
|
16
|
+
//# sourceMappingURL=tokens.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokens.js","sourceRoot":"","sources":["../../nestjs/tokens.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,mEAAmE;AACtD,QAAA,mBAAmB,GAAG,qBAAqB,CAAC;AAEzD,kDAAkD;AACrC,QAAA,iBAAiB,GAAG,mBAAmB,CAAC;AAErD,oDAAoD;AACvC,QAAA,mBAAmB,GAAG,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { Configuration } from 'oidc-provider';
|
|
2
|
+
import type { Repository } from 'typeorm';
|
|
3
|
+
import type { BaseUser, StorageAdapter } from '@nauth-toolkit/core';
|
|
4
|
+
/**
|
|
5
|
+
* A statically configured OIDC client.
|
|
6
|
+
*
|
|
7
|
+
* Mirrors `oidc-provider`'s client metadata, narrowed to the fields a nauth
|
|
8
|
+
* deployment normally sets. Secrets stay in configuration or environment, never in
|
|
9
|
+
* source.
|
|
10
|
+
*/
|
|
11
|
+
export interface NAuthOIDCClient {
|
|
12
|
+
/** Public client identifier, sent as `client_id`. */
|
|
13
|
+
client_id: string;
|
|
14
|
+
/** Client secret. Omit for a public client, which must then use PKCE. */
|
|
15
|
+
client_secret?: string;
|
|
16
|
+
/** Human-readable name, shown on the consent screen. */
|
|
17
|
+
client_name?: string;
|
|
18
|
+
/** Registered redirect URIs, matched as exact strings. */
|
|
19
|
+
redirect_uris: string[];
|
|
20
|
+
/** Grant types this client may use. @default ['authorization_code', 'refresh_token'] */
|
|
21
|
+
grant_types?: string[];
|
|
22
|
+
/**
|
|
23
|
+
* Response types. This provider implements the authorization-code flow only —
|
|
24
|
+
* the implicit and hybrid flows are deliberately unavailable.
|
|
25
|
+
*
|
|
26
|
+
* @default ['code']
|
|
27
|
+
*/
|
|
28
|
+
response_types?: 'code'[];
|
|
29
|
+
/** How the client authenticates at the token endpoint. @default 'client_secret_basic' */
|
|
30
|
+
token_endpoint_auth_method?: 'client_secret_basic' | 'client_secret_post' | 'none';
|
|
31
|
+
/** Logo shown on the consent screen. An absolute http(s) URL. */
|
|
32
|
+
logo_uri?: string;
|
|
33
|
+
/** Client home page, shown on the consent screen. An absolute http(s) URL. */
|
|
34
|
+
client_uri?: string;
|
|
35
|
+
/** Post-logout redirect URIs for RP-initiated logout. */
|
|
36
|
+
post_logout_redirect_uris?: string[];
|
|
37
|
+
/**
|
|
38
|
+
* Any other client metadata `oidc-provider` accepts.
|
|
39
|
+
*
|
|
40
|
+
* The named fields above are the ones a nauth deployment normally sets; the rest of
|
|
41
|
+
* the OpenID Connect Dynamic Registration metadata is still available here.
|
|
42
|
+
*/
|
|
43
|
+
[key: string]: unknown;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Options for {@link createNAuthOIDCProvider}.
|
|
47
|
+
*/
|
|
48
|
+
export interface NAuthOIDCOptions {
|
|
49
|
+
/**
|
|
50
|
+
* The issuer identifier — **the public origin, with no path component**.
|
|
51
|
+
*
|
|
52
|
+
* `oidc-provider` builds every endpoint URL as `new URL(path, issuer)`, and its
|
|
53
|
+
* paths are absolute, so any path on the issuer is silently discarded. Namespace
|
|
54
|
+
* the endpoints with {@link NAuthOIDCOptions.pathPrefix} instead.
|
|
55
|
+
*
|
|
56
|
+
* @example 'https://auth.example.com'
|
|
57
|
+
*/
|
|
58
|
+
issuer: string;
|
|
59
|
+
/**
|
|
60
|
+
* Path prefix every provider endpoint is served under.
|
|
61
|
+
*
|
|
62
|
+
* Applied to `routes`, so the discovery document advertises prefixed URLs.
|
|
63
|
+
* Discovery itself stays at `/.well-known/openid-configuration`, which is where
|
|
64
|
+
* OIDC Discovery requires it for an origin issuer.
|
|
65
|
+
*
|
|
66
|
+
* @default '/oidc'
|
|
67
|
+
*/
|
|
68
|
+
pathPrefix?: string;
|
|
69
|
+
/** Where the browser is sent when the provider needs the user to do something. */
|
|
70
|
+
interactionUrl: (uid: string) => string;
|
|
71
|
+
/** nauth's storage adapter. Backs every provider model; no tables are created. */
|
|
72
|
+
storage: StorageAdapter;
|
|
73
|
+
/** nauth's user repository, used to resolve accounts and release claims. */
|
|
74
|
+
userRepository: Repository<BaseUser>;
|
|
75
|
+
/**
|
|
76
|
+
* Keygrip signing keys for the provider's own cookies.
|
|
77
|
+
*
|
|
78
|
+
* Separate from nauth's JWT secrets. Rotate by prepending a new key and keeping a
|
|
79
|
+
* short history so cookies signed with the previous key still verify.
|
|
80
|
+
*/
|
|
81
|
+
cookieKeys: string[];
|
|
82
|
+
/** Statically registered clients. */
|
|
83
|
+
clients?: NAuthOIDCClient[];
|
|
84
|
+
/** JWKS used to sign id_tokens. A development key is generated when omitted. */
|
|
85
|
+
jwks?: {
|
|
86
|
+
keys: Record<string, unknown>[];
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Trust `X-Forwarded-*` headers.
|
|
90
|
+
*
|
|
91
|
+
* Required behind a reverse proxy such as Caddy — without it every generated URL is
|
|
92
|
+
* `http://`, redirect-URI checks mismatch, and `secure` cookies are refused.
|
|
93
|
+
*
|
|
94
|
+
* @default false
|
|
95
|
+
*/
|
|
96
|
+
proxy?: boolean;
|
|
97
|
+
/** Mark cookies `secure`. Leave false for plain-http local development. @default true */
|
|
98
|
+
secureCookies?: boolean;
|
|
99
|
+
/** Escape hatch for any `oidc-provider` option this wrapper does not surface. */
|
|
100
|
+
extraConfiguration?: Partial<Configuration>;
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=config.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.types.d.ts","sourceRoot":"","sources":["../../src/config.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAEpE;;;;;;GAMG;AACH,MAAM,WAAW,eAAe;I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AAC;IAEhB,yFAAyF;IACzF,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB,iFAAiF;IACjF,kBAAkB,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;CAC7C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.types.js","sourceRoot":"","sources":["../../src/config.types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type Provider from 'oidc-provider';
|
|
2
|
+
import type { Configuration } from 'oidc-provider';
|
|
3
|
+
import type { NAuthOIDCOptions } from './config.types';
|
|
4
|
+
/** The `Provider` constructor, as loaded from the ESM-only package. */
|
|
5
|
+
type ProviderCtor = new (issuer: string, configuration?: Configuration) => Provider;
|
|
6
|
+
/**
|
|
7
|
+
* Load the ESM-only `oidc-provider` from a CommonJS build.
|
|
8
|
+
*
|
|
9
|
+
* Node supports `require(esm)` unflagged from ^20.19 and ^22.12, and the package has
|
|
10
|
+
* no top-level await, so the synchronous path works on every currently supported
|
|
11
|
+
* runtime. The dynamic-import fallback covers Node 22.0–22.11, and is built through
|
|
12
|
+
* `Function` so TypeScript does not rewrite it back into a `require` — the same
|
|
13
|
+
* technique `JwtService` already uses for the ESM-only `jose`.
|
|
14
|
+
*/
|
|
15
|
+
export declare function loadProviderCtor(): Promise<ProviderCtor>;
|
|
16
|
+
/**
|
|
17
|
+
* Create an `oidc-provider` instance wired to nauth's storage and users.
|
|
18
|
+
*
|
|
19
|
+
* The provider owns a disjoint path prefix at the raw HTTP layer and never touches
|
|
20
|
+
* nauth's request abstraction. It keeps its own session; nauth stays the sole
|
|
21
|
+
* authority on *identity*, reached through `findAccount` and the interaction bridge.
|
|
22
|
+
*
|
|
23
|
+
* Note the routing arrangement: the issuer is a bare origin and every route carries
|
|
24
|
+
* the prefix. Mounting the other way round — a path-prefixed issuer with the prefix
|
|
25
|
+
* stripped from `req.url` — looks natural and is what the upstream README shows, but
|
|
26
|
+
* it is broken: `urlFor()` resolves `new URL('/auth', 'https://host/oidc')` to
|
|
27
|
+
* `https://host/auth`, so the discovery document advertises endpoints that 404.
|
|
28
|
+
*
|
|
29
|
+
* @param options - Issuer, storage, users, cookie keys and clients
|
|
30
|
+
* @param ctor - Injectable constructor, so tests need not load the real ESM module
|
|
31
|
+
* @returns A configured provider, ready to mount
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const provider = await createNAuthOIDCProvider({
|
|
36
|
+
* issuer: 'https://auth.example.com',
|
|
37
|
+
* interactionUrl: (uid) => `https://auth.example.com/interaction/${uid}`,
|
|
38
|
+
* storage: nauth.storage,
|
|
39
|
+
* userRepository,
|
|
40
|
+
* cookieKeys: [process.env.OIDC_COOKIE_SECRET!],
|
|
41
|
+
* clients: [{ client_id: 'partner', client_secret: '…', redirect_uris: ['https://partner.example/cb'] }],
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare function createNAuthOIDCProvider(options: NAuthOIDCOptions, ctor?: ProviderCtor): Promise<Provider>;
|
|
46
|
+
export {};
|
|
47
|
+
//# sourceMappingURL=create-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-provider.d.ts","sourceRoot":"","sources":["../../src/create-provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAGnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,uEAAuE;AACvE,KAAK,YAAY,GAAG,KAAK,MAAM,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,aAAa,KAAK,QAAQ,CAAC;AA4BpF;;;;;;;;GAQG;AACH,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,YAAY,CAAC,CAS9D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAsB,uBAAuB,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,QAAQ,CAAC,CAwG/G"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadProviderCtor = loadProviderCtor;
|
|
4
|
+
exports.createNAuthOIDCProvider = createNAuthOIDCProvider;
|
|
5
|
+
const storage_adapter_1 = require("./storage.adapter");
|
|
6
|
+
const find_account_1 = require("./find-account");
|
|
7
|
+
/** Every route `oidc-provider` serves, so all of them can be prefixed together. */
|
|
8
|
+
const ROUTE_NAMES = [
|
|
9
|
+
['authorization', '/auth'],
|
|
10
|
+
['token', '/token'],
|
|
11
|
+
['jwks', '/jwks'],
|
|
12
|
+
['userinfo', '/me'],
|
|
13
|
+
['introspection', '/token/introspection'],
|
|
14
|
+
['revocation', '/token/revocation'],
|
|
15
|
+
['end_session', '/session/end'],
|
|
16
|
+
['device_authorization', '/device/auth'],
|
|
17
|
+
['code_verification', '/device'],
|
|
18
|
+
['pushed_authorization_request', '/request'],
|
|
19
|
+
['registration', '/reg'],
|
|
20
|
+
['backchannel_authentication', '/backchannel'],
|
|
21
|
+
['challenge', '/challenge'],
|
|
22
|
+
['credential', '/credential'],
|
|
23
|
+
];
|
|
24
|
+
/**
|
|
25
|
+
* Load the ESM-only `oidc-provider` from a CommonJS build.
|
|
26
|
+
*
|
|
27
|
+
* Node supports `require(esm)` unflagged from ^20.19 and ^22.12, and the package has
|
|
28
|
+
* no top-level await, so the synchronous path works on every currently supported
|
|
29
|
+
* runtime. The dynamic-import fallback covers Node 22.0–22.11, and is built through
|
|
30
|
+
* `Function` so TypeScript does not rewrite it back into a `require` — the same
|
|
31
|
+
* technique `JwtService` already uses for the ESM-only `jose`.
|
|
32
|
+
*/
|
|
33
|
+
async function loadProviderCtor() {
|
|
34
|
+
try {
|
|
35
|
+
const mod = require('oidc-provider');
|
|
36
|
+
return (mod.default ?? mod);
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
const nativeImport = new Function('m', 'return import(m)');
|
|
40
|
+
const mod = (await nativeImport('oidc-provider'));
|
|
41
|
+
return (mod.default ?? mod);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Create an `oidc-provider` instance wired to nauth's storage and users.
|
|
46
|
+
*
|
|
47
|
+
* The provider owns a disjoint path prefix at the raw HTTP layer and never touches
|
|
48
|
+
* nauth's request abstraction. It keeps its own session; nauth stays the sole
|
|
49
|
+
* authority on *identity*, reached through `findAccount` and the interaction bridge.
|
|
50
|
+
*
|
|
51
|
+
* Note the routing arrangement: the issuer is a bare origin and every route carries
|
|
52
|
+
* the prefix. Mounting the other way round — a path-prefixed issuer with the prefix
|
|
53
|
+
* stripped from `req.url` — looks natural and is what the upstream README shows, but
|
|
54
|
+
* it is broken: `urlFor()` resolves `new URL('/auth', 'https://host/oidc')` to
|
|
55
|
+
* `https://host/auth`, so the discovery document advertises endpoints that 404.
|
|
56
|
+
*
|
|
57
|
+
* @param options - Issuer, storage, users, cookie keys and clients
|
|
58
|
+
* @param ctor - Injectable constructor, so tests need not load the real ESM module
|
|
59
|
+
* @returns A configured provider, ready to mount
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* const provider = await createNAuthOIDCProvider({
|
|
64
|
+
* issuer: 'https://auth.example.com',
|
|
65
|
+
* interactionUrl: (uid) => `https://auth.example.com/interaction/${uid}`,
|
|
66
|
+
* storage: nauth.storage,
|
|
67
|
+
* userRepository,
|
|
68
|
+
* cookieKeys: [process.env.OIDC_COOKIE_SECRET!],
|
|
69
|
+
* clients: [{ client_id: 'partner', client_secret: '…', redirect_uris: ['https://partner.example/cb'] }],
|
|
70
|
+
* });
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
async function createNAuthOIDCProvider(options, ctor) {
|
|
74
|
+
const Ctor = ctor ?? (await loadProviderCtor());
|
|
75
|
+
const prefix = options.pathPrefix ?? '/oidc';
|
|
76
|
+
const routes = Object.fromEntries(ROUTE_NAMES.map(([name, path]) => [name, `${prefix}${path}`]));
|
|
77
|
+
const configuration = {
|
|
78
|
+
adapter: (0, storage_adapter_1.createOIDCStorageAdapter)(options.storage),
|
|
79
|
+
findAccount: (0, find_account_1.createFindAccount)(options.userRepository),
|
|
80
|
+
clients: options.clients ?? [],
|
|
81
|
+
routes,
|
|
82
|
+
// Widen the interaction cookie to the whole origin. It is otherwise scoped to the
|
|
83
|
+
// interaction URL, and the bridge endpoints — which live under the API prefix —
|
|
84
|
+
// would never receive it, so interactionDetails() could not resolve the request.
|
|
85
|
+
cookies: {
|
|
86
|
+
keys: options.cookieKeys,
|
|
87
|
+
short: { path: '/', sameSite: 'lax', secure: options.secureCookies !== false, httpOnly: true },
|
|
88
|
+
long: { path: '/', sameSite: 'lax', secure: options.secureCookies !== false, httpOnly: true },
|
|
89
|
+
},
|
|
90
|
+
interactions: {
|
|
91
|
+
url: (_ctx, interaction) => options.interactionUrl(interaction.uid),
|
|
92
|
+
},
|
|
93
|
+
// `offline_access` must be declared for a client to be able to request it; the
|
|
94
|
+
// claim scopes below (email, profile, phone) are added implicitly by `claims`.
|
|
95
|
+
scopes: ['openid', 'offline_access'],
|
|
96
|
+
claims: {
|
|
97
|
+
openid: ['sub'],
|
|
98
|
+
email: ['email', 'email_verified'],
|
|
99
|
+
profile: ['name', 'given_name', 'family_name', 'preferred_username', 'updated_at'],
|
|
100
|
+
phone: ['phone_number', 'phone_number_verified'],
|
|
101
|
+
},
|
|
102
|
+
features: {
|
|
103
|
+
// Both are off by default upstream, and both are load-bearing for a resource
|
|
104
|
+
// server validating tokens.
|
|
105
|
+
//
|
|
106
|
+
// `allowedPolicy` is tightened deliberately. Upstream lets any authenticated
|
|
107
|
+
// client introspect or revoke any token, which means one registered partner can
|
|
108
|
+
// probe another's tokens for validity, subject and scope — or revoke them. A
|
|
109
|
+
// client is restricted here to tokens it was itself issued.
|
|
110
|
+
introspection: {
|
|
111
|
+
enabled: true,
|
|
112
|
+
allowedPolicy: async (_ctx, client, token) => token.clientId === client.clientId,
|
|
113
|
+
},
|
|
114
|
+
revocation: {
|
|
115
|
+
enabled: true,
|
|
116
|
+
allowedPolicy: async (_ctx, client, token) => token.clientId === client.clientId,
|
|
117
|
+
},
|
|
118
|
+
// The built-in demo login screens must never be reachable: nauth owns login.
|
|
119
|
+
devInteractions: { enabled: false },
|
|
120
|
+
},
|
|
121
|
+
// Explicit lifetimes. Upstream warns on every default, and silent defaults are a
|
|
122
|
+
// poor thing to discover in production.
|
|
123
|
+
ttl: {
|
|
124
|
+
AccessToken: 60 * 60,
|
|
125
|
+
AuthorizationCode: 60,
|
|
126
|
+
IdToken: 60 * 60,
|
|
127
|
+
RefreshToken: 30 * 24 * 60 * 60,
|
|
128
|
+
Interaction: 15 * 60,
|
|
129
|
+
Session: 14 * 24 * 60 * 60,
|
|
130
|
+
Grant: 14 * 24 * 60 * 60,
|
|
131
|
+
},
|
|
132
|
+
// Authorization code only.
|
|
133
|
+
//
|
|
134
|
+
// Upstream also enables `id_token`, `code id_token` and `none` — the implicit and
|
|
135
|
+
// hybrid flows, which return tokens in the URL fragment where they leak through
|
|
136
|
+
// browser history, referrers and logs. Both are removed in OAuth 2.1 and advised
|
|
137
|
+
// against by RFC 9700, so they are switched off here rather than left to each
|
|
138
|
+
// consumer to notice and disable.
|
|
139
|
+
responseTypes: ['code'],
|
|
140
|
+
// PKCE is required for every client, not just public ones (RFC 9700).
|
|
141
|
+
pkce: { required: () => true },
|
|
142
|
+
// Issue a refresh token whenever the client is registered for the grant.
|
|
143
|
+
//
|
|
144
|
+
// The upstream default additionally requires the `offline_access` scope. That is
|
|
145
|
+
// the letter of OpenID Connect, but it surprises integrators migrating from
|
|
146
|
+
// providers that do not require it, and it fails silently — the token response is
|
|
147
|
+
// simply missing `refresh_token` with no error to explain why. Registering the
|
|
148
|
+
// grant is the deliberate act here, so that is what this keys off.
|
|
149
|
+
issueRefreshToken: async (_ctx, client, _code) => client.grantTypeAllowed('refresh_token'),
|
|
150
|
+
...(options.jwks ? { jwks: options.jwks } : {}),
|
|
151
|
+
...options.extraConfiguration,
|
|
152
|
+
};
|
|
153
|
+
const provider = new Ctor(options.issuer, configuration);
|
|
154
|
+
if (options.proxy) {
|
|
155
|
+
provider.proxy = true;
|
|
156
|
+
}
|
|
157
|
+
return provider;
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=create-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-provider.js","sourceRoot":"","sources":["../../src/create-provider.ts"],"names":[],"mappings":";;AA4CA,4CASC;AA+BD,0DAwGC;AA1LD,uDAA6D;AAC7D,iDAAmD;AAcnD,mFAAmF;AACnF,MAAM,WAAW,GAAG;IAClB,CAAC,eAAe,EAAE,OAAO,CAAC;IAC1B,CAAC,OAAO,EAAE,QAAQ,CAAC;IACnB,CAAC,MAAM,EAAE,OAAO,CAAC;IACjB,CAAC,UAAU,EAAE,KAAK,CAAC;IACnB,CAAC,eAAe,EAAE,sBAAsB,CAAC;IACzC,CAAC,YAAY,EAAE,mBAAmB,CAAC;IACnC,CAAC,aAAa,EAAE,cAAc,CAAC;IAC/B,CAAC,sBAAsB,EAAE,cAAc,CAAC;IACxC,CAAC,mBAAmB,EAAE,SAAS,CAAC;IAChC,CAAC,8BAA8B,EAAE,UAAU,CAAC;IAC5C,CAAC,cAAc,EAAE,MAAM,CAAC;IACxB,CAAC,4BAA4B,EAAE,cAAc,CAAC;IAC9C,CAAC,WAAW,EAAE,YAAY,CAAC;IAC3B,CAAC,YAAY,EAAE,aAAa,CAAC;CACrB,CAAC;AAEX;;;;;;;;GAQG;AACI,KAAK,UAAU,gBAAgB;IACpC,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,OAAO,CAAC,eAAe,CAA8C,CAAC;QAClF,OAAO,CAAC,G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ACrB,OAAO,EAAE,EAAE,GAAG,EAAE;YAChB,YAAY,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE;YAC/B,WAAW,EAAE,EAAE,GAAG,EAAE;YACpB,OAAO,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE;YAC1B,KAAK,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE;SACzB;QAED,2BAA2B;QAC3B,EAAE;QACF,kFAAkF;QAClF,gFAAgF;QAChF,iFAAiF;QACjF,8EAA8E;QAC9E,kCAAkC;QAClC,aAAa,EAAE,CAAC,MAAM,CAAC;QAEvB,sEAAsE;QACtE,IAAI,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE;QAE9B,yEAAyE;QACzE,EAAE;QACF,iFAAiF;QACjF,4EAA4E;QAC5E,kFAAkF;QAClF,+EAA+E;QAC/E,mEAAmE;QACnE,iBAAiB,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,gBAAgB,CAAC,eAAe,CAAC;QAE1F,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,IAA6B,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACxE,GAAG,OAAO,CAAC,kBAAkB;KAC9B,CAAC;IAEF,MAAM,QAAQ,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAEzD,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;QAClB,QAAQ,CAAC,KAAK,GAAG,IAAI,CAAC;IACxB,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { AccountClaims } from 'oidc-provider';
|
|
2
|
+
import type { Repository } from 'typeorm';
|
|
3
|
+
import type { BaseUser } from '@nauth-toolkit/core';
|
|
4
|
+
/**
|
|
5
|
+
* The shape `oidc-provider` expects back from `findAccount`.
|
|
6
|
+
*/
|
|
7
|
+
export interface OIDCAccount {
|
|
8
|
+
accountId: string;
|
|
9
|
+
claims(use: string, scope: string): Promise<AccountClaims>;
|
|
10
|
+
/** `oidc-provider` allows arbitrary extra account properties. */
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Build the `findAccount` function that resolves an nauth user for `oidc-provider`.
|
|
15
|
+
*
|
|
16
|
+
* This is one of only two seams between nauth and the provider, and it is a pure data
|
|
17
|
+
* lookup — no HTTP, no request context. The account identifier is the user's external
|
|
18
|
+
* `sub`, never the internal row id.
|
|
19
|
+
*
|
|
20
|
+
* Claims are released strictly by granted scope: `sub` always, email claims only for
|
|
21
|
+
* `email`, name claims only for `profile`, phone claims only for `phone`. A client
|
|
22
|
+
* therefore never learns more about a user than it was consented to.
|
|
23
|
+
*
|
|
24
|
+
* @param userRepository - nauth's user repository
|
|
25
|
+
* @returns A `findAccount` implementation for the provider configuration
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* new Provider(issuer, { findAccount: createFindAccount(userRepository) });
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare function createFindAccount(userRepository: Repository<BaseUser>): (ctx: unknown, sub: string) => Promise<OIDCAccount | undefined>;
|
|
33
|
+
//# sourceMappingURL=find-account.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"find-account.d.ts","sourceRoot":"","sources":["../../src/find-account.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAWpD;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IAC3D,iEAAiE;IACjE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,iBAAiB,CAC/B,cAAc,EAAE,UAAU,CAAC,QAAQ,CAAC,GACnC,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,CAmDjE"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createFindAccount = createFindAccount;
|
|
4
|
+
/**
|
|
5
|
+
* Build the `findAccount` function that resolves an nauth user for `oidc-provider`.
|
|
6
|
+
*
|
|
7
|
+
* This is one of only two seams between nauth and the provider, and it is a pure data
|
|
8
|
+
* lookup — no HTTP, no request context. The account identifier is the user's external
|
|
9
|
+
* `sub`, never the internal row id.
|
|
10
|
+
*
|
|
11
|
+
* Claims are released strictly by granted scope: `sub` always, email claims only for
|
|
12
|
+
* `email`, name claims only for `profile`, phone claims only for `phone`. A client
|
|
13
|
+
* therefore never learns more about a user than it was consented to.
|
|
14
|
+
*
|
|
15
|
+
* @param userRepository - nauth's user repository
|
|
16
|
+
* @returns A `findAccount` implementation for the provider configuration
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* new Provider(issuer, { findAccount: createFindAccount(userRepository) });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
function createFindAccount(userRepository) {
|
|
24
|
+
return async (_ctx, sub) => {
|
|
25
|
+
const user = await userRepository.findOne({ where: { sub } });
|
|
26
|
+
// A disabled or deleted account resolves to nothing, so the provider drops the
|
|
27
|
+
// session rather than minting tokens for it.
|
|
28
|
+
if (!user || !user.isActive) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
accountId: user.sub,
|
|
33
|
+
async claims(_use, scope) {
|
|
34
|
+
const scopes = new Set((scope ?? '').split(/\s+/).filter(Boolean));
|
|
35
|
+
const claims = { sub: user.sub };
|
|
36
|
+
if (scopes.has('email')) {
|
|
37
|
+
claims.email = user.email;
|
|
38
|
+
claims.email_verified = user.isEmailVerified;
|
|
39
|
+
}
|
|
40
|
+
if (scopes.has('profile')) {
|
|
41
|
+
const profile = {};
|
|
42
|
+
const full = [user.firstName, user.lastName].filter(Boolean).join(' ').trim();
|
|
43
|
+
if (full) {
|
|
44
|
+
profile.name = full;
|
|
45
|
+
}
|
|
46
|
+
if (user.firstName) {
|
|
47
|
+
profile.given_name = user.firstName;
|
|
48
|
+
}
|
|
49
|
+
if (user.lastName) {
|
|
50
|
+
profile.family_name = user.lastName;
|
|
51
|
+
}
|
|
52
|
+
if (user.username) {
|
|
53
|
+
profile.preferred_username = user.username;
|
|
54
|
+
}
|
|
55
|
+
if (user.updatedAt) {
|
|
56
|
+
profile.updated_at = Math.floor(new Date(user.updatedAt).getTime() / 1000);
|
|
57
|
+
}
|
|
58
|
+
Object.assign(claims, profile);
|
|
59
|
+
}
|
|
60
|
+
if (scopes.has('phone') && user.phone) {
|
|
61
|
+
claims.phone_number = user.phone;
|
|
62
|
+
claims.phone_number_verified = user.isPhoneVerified;
|
|
63
|
+
}
|
|
64
|
+
return claims;
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=find-account.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"find-account.js","sourceRoot":"","sources":["../../src/find-account.ts"],"names":[],"mappings":";;AA0CA,8CAqDC;AAxED;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,iBAAiB,CAC/B,cAAoC;IAEpC,OA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C,SAAS,CAAC;oBACtC,CAAC;oBACD,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;wBAClB,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,QAAQ,CAAC;oBACtC,CAAC;oBACD,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;wBAClB,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC,QAAQ,CAAC;oBAC7C,CAAC;oBACD,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;wBACnB,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;oBAC7E,CAAC;oBACD,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBACjC,CAAC;gBAED,IAAI,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;oBACtC,MAAM,CAAC,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC;oBACjC,MAAM,CAAC,qBAAqB,GAAG,IAAI,CAAC,eAAe,CAAC;gBACtD,CAAC;gBAED,OAAO,MAAM,CAAC;YAChB,CAAC;SACF,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenID Connect provider for nauth-toolkit.
|
|
3
|
+
*
|
|
4
|
+
* Turns an nauth-backed application into an OAuth2 authorization server and OpenID
|
|
5
|
+
* Connect provider, so third parties can offer "Sign in with <your app>". The protocol
|
|
6
|
+
* itself is implemented by the OpenID Certified `oidc-provider` library; this package
|
|
7
|
+
* supplies the three things it needs from nauth — storage, accounts, and a login and
|
|
8
|
+
* consent flow — and nothing else.
|
|
9
|
+
*
|
|
10
|
+
* nauth remains the sole authority on identity: the whole challenge state machine
|
|
11
|
+
* (forced password change, email and phone verification, MFA setup and verification,
|
|
12
|
+
* adaptive risk) runs before the bridge ever reports a completed login.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import { createNAuthOIDCProvider, mountOIDCProviderExpress } from '@nauth-toolkit/oidc-provider';
|
|
17
|
+
*
|
|
18
|
+
* const provider = await createNAuthOIDCProvider({
|
|
19
|
+
* issuer: 'https://auth.example.com', // an origin, never a path
|
|
20
|
+
* interactionUrl: (uid) => `https://auth.example.com/interaction/${uid}`,
|
|
21
|
+
* storage: nauth.storage,
|
|
22
|
+
* userRepository,
|
|
23
|
+
* cookieKeys: [process.env.OIDC_COOKIE_SECRET!],
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* mountOIDCProviderExpress(app, provider); // before body parsers
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export { createNAuthOIDCProvider, loadProviderCtor } from './create-provider';
|
|
30
|
+
export { createOIDCStorageAdapter, NAuthOIDCAdapter } from './storage.adapter';
|
|
31
|
+
export { createFindAccount } from './find-account';
|
|
32
|
+
export type { OIDCAccount } from './find-account';
|
|
33
|
+
export { OIDCInteractionBridge } from './interaction-bridge';
|
|
34
|
+
export type { InteractionStateDTO, InteractionRedirectDTO } from './interaction-bridge';
|
|
35
|
+
export { mountOIDCProviderExpress, isProviderPath } from './mount/express';
|
|
36
|
+
export { toRawHttp } from './raw-http';
|
|
37
|
+
export { OIDCSessionTerminator } from './session-termination';
|
|
38
|
+
export { createOIDCRateLimiter } from './rate-limit';
|
|
39
|
+
export type { OIDCRateLimitConfig, OIDCEndpointLimit } from './rate-limit';
|
|
40
|
+
export type { NAuthOIDCOptions, NAuthOIDCClient } from './config.types';
|
|
41
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC9E,OAAO,EAAE,wBAAwB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,YAAY,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,YAAY,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AACxF,OAAO,EAAE,wBAAwB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAC3E,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACrD,YAAY,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAC3E,YAAY,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC"}
|