@opencloudcms/oauth2 0.0.0-stage → 0.1.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 +397 -2
- package/dist/audit/audit.service.d.ts +18 -0
- package/dist/audit/audit.service.js +61 -0
- package/dist/audit/audit.service.js.map +1 -0
- package/dist/bff/auth.controller.d.ts +41 -0
- package/dist/bff/auth.controller.js +269 -0
- package/dist/bff/auth.controller.js.map +1 -0
- package/dist/bff/cookies.d.ts +11 -0
- package/dist/bff/cookies.js +43 -0
- package/dist/bff/cookies.js.map +1 -0
- package/dist/bff/oidc-client.d.ts +73 -0
- package/dist/bff/oidc-client.js +158 -0
- package/dist/bff/oidc-client.js.map +1 -0
- package/dist/bff/session-refresher.d.ts +27 -0
- package/dist/bff/session-refresher.js +95 -0
- package/dist/bff/session-refresher.js.map +1 -0
- package/dist/bff/session.store.d.ts +88 -0
- package/dist/bff/session.store.js +167 -0
- package/dist/bff/session.store.js.map +1 -0
- package/dist/clients/clients.d.ts +37 -0
- package/dist/clients/clients.js +107 -0
- package/dist/clients/clients.js.map +1 -0
- package/dist/config/schema.d.ts +91 -0
- package/dist/config/schema.js +129 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/constants.d.ts +45 -0
- package/dist/constants.js +42 -0
- package/dist/constants.js.map +1 -0
- package/dist/cors/cors-origins.controller.d.ts +19 -0
- package/dist/cors/cors-origins.controller.js +122 -0
- package/dist/cors/cors-origins.controller.js.map +1 -0
- package/dist/cors/cors-origins.service.d.ts +73 -0
- package/dist/cors/cors-origins.service.js +287 -0
- package/dist/cors/cors-origins.service.js.map +1 -0
- package/dist/cors/customer-cors.middleware.d.ts +22 -0
- package/dist/cors/customer-cors.middleware.js +84 -0
- package/dist/cors/customer-cors.middleware.js.map +1 -0
- package/dist/customers/account.controller.d.ts +91 -0
- package/dist/customers/account.controller.js +443 -0
- package/dist/customers/account.controller.js.map +1 -0
- package/dist/customers/auth-hooks.d.ts +47 -0
- package/dist/customers/auth-hooks.js +79 -0
- package/dist/customers/auth-hooks.js.map +1 -0
- package/dist/customers/customer-auth.controller.d.ts +54 -0
- package/dist/customers/customer-auth.controller.js +287 -0
- package/dist/customers/customer-auth.controller.js.map +1 -0
- package/dist/customers/customer-sessions.revoker.d.ts +21 -0
- package/dist/customers/customer-sessions.revoker.js +47 -0
- package/dist/customers/customer-sessions.revoker.js.map +1 -0
- package/dist/customers/customer.service.d.ts +53 -0
- package/dist/customers/customer.service.js +229 -0
- package/dist/customers/customer.service.js.map +1 -0
- package/dist/customers/customers-admin.controller.d.ts +21 -0
- package/dist/customers/customers-admin.controller.js +134 -0
- package/dist/customers/customers-admin.controller.js.map +1 -0
- package/dist/customers/identifier.d.ts +6 -0
- package/dist/customers/identifier.js +27 -0
- package/dist/customers/identifier.js.map +1 -0
- package/dist/customers/sign-in-settings.controller.d.ts +27 -0
- package/dist/customers/sign-in-settings.controller.js +112 -0
- package/dist/customers/sign-in-settings.controller.js.map +1 -0
- package/dist/customers/sign-in-settings.service.d.ts +35 -0
- package/dist/customers/sign-in-settings.service.js +130 -0
- package/dist/customers/sign-in-settings.service.js.map +1 -0
- package/dist/db/migrations/index.d.ts +2 -0
- package/dist/db/migrations/index.js +14 -0
- package/dist/db/migrations/index.js.map +1 -0
- package/dist/db/migrations/oauth2_0001_init.d.ts +2 -0
- package/dist/db/migrations/oauth2_0001_init.js +127 -0
- package/dist/db/migrations/oauth2_0001_init.js.map +1 -0
- package/dist/db/migrations/oauth2_0002_user_locale.d.ts +3 -0
- package/dist/db/migrations/oauth2_0002_user_locale.js +13 -0
- package/dist/db/migrations/oauth2_0002_user_locale.js.map +1 -0
- package/dist/db/migrations/oauth2_0003_groups.d.ts +6 -0
- package/dist/db/migrations/oauth2_0003_groups.js +46 -0
- package/dist/db/migrations/oauth2_0003_groups.js.map +1 -0
- package/dist/db/migrations/oauth2_0004_customers.d.ts +3 -0
- package/dist/db/migrations/oauth2_0004_customers.js +108 -0
- package/dist/db/migrations/oauth2_0004_customers.js.map +1 -0
- package/dist/db/types.d.ts +176 -0
- package/dist/db/types.js +3 -0
- package/dist/db/types.js.map +1 -0
- package/dist/errors.d.ts +28 -0
- package/dist/errors.js +115 -0
- package/dist/errors.js.map +1 -0
- package/dist/groups/groups.controller.d.ts +28 -0
- package/dist/groups/groups.controller.js +126 -0
- package/dist/groups/groups.controller.js.map +1 -0
- package/dist/groups/groups.service.d.ts +38 -0
- package/dist/groups/groups.service.js +134 -0
- package/dist/groups/groups.service.js.map +1 -0
- package/dist/guard/auth.guard.d.ts +29 -0
- package/dist/guard/auth.guard.js +119 -0
- package/dist/guard/auth.guard.js.map +1 -0
- package/dist/guard/current-user.decorator.d.ts +33 -0
- package/dist/guard/current-user.decorator.js +16 -0
- package/dist/guard/current-user.decorator.js.map +1 -0
- package/dist/guard/customer-auth.decorator.d.ts +26 -0
- package/dist/guard/customer-auth.decorator.js +16 -0
- package/dist/guard/customer-auth.decorator.js.map +1 -0
- package/dist/guard/customer-authenticator.d.ts +58 -0
- package/dist/guard/customer-authenticator.js +215 -0
- package/dist/guard/customer-authenticator.js.map +1 -0
- package/dist/guard/public.decorator.d.ts +2 -0
- package/dist/guard/public.decorator.js +8 -0
- package/dist/guard/public.decorator.js.map +1 -0
- package/dist/guard/session-auth.service.d.ts +28 -0
- package/dist/guard/session-auth.service.js +125 -0
- package/dist/guard/session-auth.service.js.map +1 -0
- package/dist/idp/identity-linker.d.ts +19 -0
- package/dist/idp/identity-linker.js +93 -0
- package/dist/idp/identity-linker.js.map +1 -0
- package/dist/idp/identity-provider.d.ts +54 -0
- package/dist/idp/identity-provider.js +36 -0
- package/dist/idp/identity-provider.js.map +1 -0
- package/dist/idp/idp.controller.d.ts +36 -0
- package/dist/idp/idp.controller.js +232 -0
- package/dist/idp/idp.controller.js.map +1 -0
- package/dist/idp/oidc.identity-provider.d.ts +42 -0
- package/dist/idp/oidc.identity-provider.js +96 -0
- package/dist/idp/oidc.identity-provider.js.map +1 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.js +98 -0
- package/dist/index.js.map +1 -0
- package/dist/interaction/customer-interaction.controller.d.ts +64 -0
- package/dist/interaction/customer-interaction.controller.js +336 -0
- package/dist/interaction/customer-interaction.controller.js.map +1 -0
- package/dist/interaction/interaction.controller.d.ts +36 -0
- package/dist/interaction/interaction.controller.js +175 -0
- package/dist/interaction/interaction.controller.js.map +1 -0
- package/dist/interaction/interaction.service.d.ts +40 -0
- package/dist/interaction/interaction.service.js +102 -0
- package/dist/interaction/interaction.service.js.map +1 -0
- package/dist/maintenance/cleanup.service.d.ts +22 -0
- package/dist/maintenance/cleanup.service.js +77 -0
- package/dist/maintenance/cleanup.service.js.map +1 -0
- package/dist/oauth2.module.d.ts +37 -0
- package/dist/oauth2.module.js +214 -0
- package/dist/oauth2.module.js.map +1 -0
- package/dist/otp/otp-guard.d.ts +7 -0
- package/dist/otp/otp-guard.js +27 -0
- package/dist/otp/otp-guard.js.map +1 -0
- package/dist/otp/otp.service.d.ts +57 -0
- package/dist/otp/otp.service.js +202 -0
- package/dist/otp/otp.service.js.map +1 -0
- package/dist/otp/otp.types.d.ts +36 -0
- package/dist/otp/otp.types.js +34 -0
- package/dist/otp/otp.types.js.map +1 -0
- package/dist/otp/storefront-boot-check.d.ts +13 -0
- package/dist/otp/storefront-boot-check.js +53 -0
- package/dist/otp/storefront-boot-check.js.map +1 -0
- package/dist/permissions.d.ts +12 -0
- package/dist/permissions.js +24 -0
- package/dist/permissions.js.map +1 -0
- package/dist/provider/kysely.adapter.d.ts +27 -0
- package/dist/provider/kysely.adapter.js +79 -0
- package/dist/provider/kysely.adapter.js.map +1 -0
- package/dist/provider/provider.factory.d.ts +101 -0
- package/dist/provider/provider.factory.js +377 -0
- package/dist/provider/provider.factory.js.map +1 -0
- package/dist/provider/provider.service.d.ts +60 -0
- package/dist/provider/provider.service.js +200 -0
- package/dist/provider/provider.service.js.map +1 -0
- package/dist/provider/signing-keys.d.ts +19 -0
- package/dist/provider/signing-keys.js +41 -0
- package/dist/provider/signing-keys.js.map +1 -0
- package/dist/register-migrations.d.ts +1 -0
- package/dist/register-migrations.js +7 -0
- package/dist/register-migrations.js.map +1 -0
- package/dist/security/crypto.d.ts +6 -0
- package/dist/security/crypto.js +29 -0
- package/dist/security/crypto.js.map +1 -0
- package/dist/security/email.d.ts +1 -0
- package/dist/security/email.js +7 -0
- package/dist/security/email.js.map +1 -0
- package/dist/security/origin.d.ts +1 -0
- package/dist/security/origin.js +15 -0
- package/dist/security/origin.js.map +1 -0
- package/dist/security/password.d.ts +12 -0
- package/dist/security/password.js +92 -0
- package/dist/security/password.js.map +1 -0
- package/dist/security/rate-limiter.d.ts +25 -0
- package/dist/security/rate-limiter.js +52 -0
- package/dist/security/rate-limiter.js.map +1 -0
- package/dist/security/return-to.d.ts +6 -0
- package/dist/security/return-to.js +33 -0
- package/dist/security/return-to.js.map +1 -0
- package/dist/security/validate.d.ts +3 -0
- package/dist/security/validate.js +14 -0
- package/dist/security/validate.js.map +1 -0
- package/dist/settings/settings.provider.d.ts +11 -0
- package/dist/settings/settings.provider.js +20 -0
- package/dist/settings/settings.provider.js.map +1 -0
- package/dist/setup/bootstrap.service.d.ts +24 -0
- package/dist/setup/bootstrap.service.js +117 -0
- package/dist/setup/bootstrap.service.js.map +1 -0
- package/dist/setup/setup-state.d.ts +8 -0
- package/dist/setup/setup-state.js +42 -0
- package/dist/setup/setup-state.js.map +1 -0
- package/dist/setup/setup.controller.d.ts +23 -0
- package/dist/setup/setup.controller.js +96 -0
- package/dist/setup/setup.controller.js.map +1 -0
- package/dist/users/password.controller.d.ts +19 -0
- package/dist/users/password.controller.js +87 -0
- package/dist/users/password.controller.js.map +1 -0
- package/dist/users/user.service.d.ts +114 -0
- package/dist/users/user.service.js +336 -0
- package/dist/users/user.service.js.map +1 -0
- package/dist/users/users.controller.d.ts +43 -0
- package/dist/users/users.controller.js +188 -0
- package/dist/users/users.controller.js.map +1 -0
- package/package.json +75 -3
|
@@ -0,0 +1,269 @@
|
|
|
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.AuthController = void 0;
|
|
16
|
+
const node_crypto_1 = require("node:crypto");
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const schema_1 = require("@opencloudcms/schema");
|
|
19
|
+
const zod_1 = require("zod");
|
|
20
|
+
const audit_service_1 = require("../audit/audit.service");
|
|
21
|
+
const constants_1 = require("../constants");
|
|
22
|
+
const errors_1 = require("../errors");
|
|
23
|
+
const public_decorator_1 = require("../guard/public.decorator");
|
|
24
|
+
const session_auth_service_1 = require("../guard/session-auth.service");
|
|
25
|
+
const crypto_1 = require("../security/crypto");
|
|
26
|
+
const validate_1 = require("../security/validate");
|
|
27
|
+
const return_to_1 = require("../security/return-to");
|
|
28
|
+
const setup_state_1 = require("../setup/setup-state");
|
|
29
|
+
const user_service_1 = require("../users/user.service");
|
|
30
|
+
const cookies_1 = require("./cookies");
|
|
31
|
+
const oidc_client_1 = require("./oidc-client");
|
|
32
|
+
const session_store_1 = require("./session.store");
|
|
33
|
+
const LOGIN_COOKIE_PATH = '/api/auth';
|
|
34
|
+
const LOGIN_COOKIE_MAX_AGE = 600;
|
|
35
|
+
const localeBody = zod_1.z.object({
|
|
36
|
+
locale: zod_1.z.string().nullable().refine((v) => v === null || (0, schema_1.isLocale)(v), { message: 'Unsupported locale' }),
|
|
37
|
+
});
|
|
38
|
+
const random = () => (0, node_crypto_1.randomBytes)(32).toString('base64url');
|
|
39
|
+
const loginError = (code) => `/admin/login?error=${code}`;
|
|
40
|
+
const first = (v) => typeof v === 'string' ? v : Array.isArray(v) && typeof v[0] === 'string' ? v[0] : undefined;
|
|
41
|
+
/**
|
|
42
|
+
* BFF side of spec §6.3 (steps 1–2 and 6), §6.5 (`me`) and §6.6 (`logout`): the server is the confidential
|
|
43
|
+
* client; the browser only ever gets `oc_login` (sealed PKCE/state) and `oc_session` (random id). No token
|
|
44
|
+
* leaves the server. login/callback/me are public (spec §3); logout goes through AuthGuard (Origin + session).
|
|
45
|
+
*/
|
|
46
|
+
let AuthController = class AuthController {
|
|
47
|
+
settings;
|
|
48
|
+
oidc;
|
|
49
|
+
sessions;
|
|
50
|
+
users;
|
|
51
|
+
setup;
|
|
52
|
+
auth;
|
|
53
|
+
audit;
|
|
54
|
+
revoker;
|
|
55
|
+
logger = new common_1.Logger('OAuth2');
|
|
56
|
+
cookieKey;
|
|
57
|
+
secure;
|
|
58
|
+
constructor(cfg, settings, oidc, sessions, users, setup, auth, audit, revoker) {
|
|
59
|
+
this.settings = settings;
|
|
60
|
+
this.oidc = oidc;
|
|
61
|
+
this.sessions = sessions;
|
|
62
|
+
this.users = users;
|
|
63
|
+
this.setup = setup;
|
|
64
|
+
this.auth = auth;
|
|
65
|
+
this.audit = audit;
|
|
66
|
+
this.revoker = revoker;
|
|
67
|
+
this.cookieKey = (0, crypto_1.deriveKey)(cfg.secret, 'cookie');
|
|
68
|
+
this.secure = (0, cookies_1.isSecureUrl)(cfg.publicUrl);
|
|
69
|
+
}
|
|
70
|
+
async login(req, res) {
|
|
71
|
+
const loginHint = first(req.query.login_hint);
|
|
72
|
+
const st = {
|
|
73
|
+
state: random(),
|
|
74
|
+
nonce: random(),
|
|
75
|
+
verifier: random(),
|
|
76
|
+
returnTo: (0, return_to_1.sanitizeReturnTo)(first(req.query.returnTo)),
|
|
77
|
+
};
|
|
78
|
+
const codeChallenge = (0, node_crypto_1.createHash)('sha256').update(st.verifier).digest('base64url');
|
|
79
|
+
res.setHeader('Cache-Control', 'no-store');
|
|
80
|
+
let url;
|
|
81
|
+
try {
|
|
82
|
+
url = await this.oidc.buildLoginUrl({
|
|
83
|
+
state: st.state,
|
|
84
|
+
nonce: st.nonce,
|
|
85
|
+
codeChallenge,
|
|
86
|
+
loginHint: loginHint || undefined,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
catch (e) {
|
|
90
|
+
// e.g. discovery via internalUrl failed. §8: redirect-chain errors go to the login page.
|
|
91
|
+
this.fail('BFF login: discovery failed', e);
|
|
92
|
+
return res.redirect(302, loginError('login_failed'));
|
|
93
|
+
}
|
|
94
|
+
res.append('Set-Cookie', (0, cookies_1.serializeCookie)(constants_1.LOGIN_COOKIE, (0, crypto_1.seal)(this.cookieKey, JSON.stringify(st)), {
|
|
95
|
+
path: LOGIN_COOKIE_PATH,
|
|
96
|
+
maxAge: LOGIN_COOKIE_MAX_AGE,
|
|
97
|
+
secure: this.secure,
|
|
98
|
+
}));
|
|
99
|
+
res.redirect(302, url.toString());
|
|
100
|
+
}
|
|
101
|
+
async callback(req, res) {
|
|
102
|
+
res.setHeader('Cache-Control', 'no-store');
|
|
103
|
+
// oc_login is single-use whatever the outcome.
|
|
104
|
+
res.append('Set-Cookie', (0, cookies_1.serializeCookie)(constants_1.LOGIN_COOKIE, '', { path: LOGIN_COOKIE_PATH, maxAge: 0, secure: this.secure }));
|
|
105
|
+
const st = this.readLoginState((0, cookies_1.parseCookies)(req.headers.cookie)[constants_1.LOGIN_COOKIE]);
|
|
106
|
+
if (!st || first(req.query.state) !== st.state)
|
|
107
|
+
return res.redirect(302, loginError('invalid_state'));
|
|
108
|
+
const providerError = first(req.query.error);
|
|
109
|
+
if (providerError !== undefined) {
|
|
110
|
+
return res.redirect(302, loginError(/^[a-z_]+$/.test(providerError) ? providerError : 'login_failed'));
|
|
111
|
+
}
|
|
112
|
+
// The provider redirected the browser to publicUrl + /api/auth/callback; rebuild that URL rather than
|
|
113
|
+
// trusting Host (behind a TLS proxy the request reaches us on the internal address).
|
|
114
|
+
const currentUrl = new URL(this.oidc.redirectUri);
|
|
115
|
+
currentUrl.search = new URL(req.originalUrl ?? req.url, 'http://internal').search;
|
|
116
|
+
let tokens;
|
|
117
|
+
try {
|
|
118
|
+
tokens = await this.oidc.exchange(currentUrl, { verifier: st.verifier, state: st.state, nonce: st.nonce });
|
|
119
|
+
}
|
|
120
|
+
catch (e) {
|
|
121
|
+
this.fail('BFF code exchange failed', e);
|
|
122
|
+
return res.redirect(302, loginError('login_failed'));
|
|
123
|
+
}
|
|
124
|
+
let sessionCookie;
|
|
125
|
+
try {
|
|
126
|
+
const userAgent = first(req.headers['user-agent']);
|
|
127
|
+
const { cookieValue } = await this.sessions.create(tokens.sub, tokens, { ip: req.ip, userAgent });
|
|
128
|
+
const ttl = await this.settings.getTtls();
|
|
129
|
+
await this.users.touchLogin(tokens.sub);
|
|
130
|
+
sessionCookie = (0, cookies_1.serializeCookie)(constants_1.SESSION_COOKIE, cookieValue, {
|
|
131
|
+
path: '/',
|
|
132
|
+
maxAge: ttl.sessionAbsolute,
|
|
133
|
+
secure: this.secure,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
catch (e) {
|
|
137
|
+
// e.g. the user was deleted between the interaction and the callback (FK violation).
|
|
138
|
+
this.fail('BFF session creation failed', e);
|
|
139
|
+
return res.redirect(302, loginError('login_failed'));
|
|
140
|
+
}
|
|
141
|
+
res.append('Set-Cookie', sessionCookie);
|
|
142
|
+
res.redirect(302, st.returnTo);
|
|
143
|
+
}
|
|
144
|
+
/** Public so it can answer setup_required itself; otherwise the guard's own session validation. */
|
|
145
|
+
async me(req, res) {
|
|
146
|
+
res.setHeader('Cache-Control', 'no-store');
|
|
147
|
+
if (await this.setup.isRequired())
|
|
148
|
+
throw new errors_1.AuthError('setup_required', 409, 'Setup is required');
|
|
149
|
+
return this.auth.authenticate(req, res);
|
|
150
|
+
}
|
|
151
|
+
/** Guarded (session + Origin): updates the caller's admin language; answers like `GET /me`. */
|
|
152
|
+
async updateMe(req, body) {
|
|
153
|
+
const { locale } = (0, validate_1.parseBody)(localeBody, body ?? {});
|
|
154
|
+
await this.users.setLocale(req.user.id, locale, {
|
|
155
|
+
ip: req.ip,
|
|
156
|
+
userAgent: first(req.headers['user-agent']),
|
|
157
|
+
});
|
|
158
|
+
const user = (await this.users.findById(req.user.id));
|
|
159
|
+
return { ...req.user, locale: user.locale };
|
|
160
|
+
}
|
|
161
|
+
async logout(req, res) {
|
|
162
|
+
res.setHeader('Cache-Control', 'no-store');
|
|
163
|
+
const cookie = (0, cookies_1.parseCookies)(req.headers.cookie)[constants_1.SESSION_COOKIE];
|
|
164
|
+
// The guard has just validated (and possibly refreshed) this session, so it is readable.
|
|
165
|
+
const session = cookie ? await this.sessions.get(cookie).catch(() => undefined) : undefined;
|
|
166
|
+
if (session?.refreshToken) {
|
|
167
|
+
try {
|
|
168
|
+
await this.oidc.revoke(session.refreshToken);
|
|
169
|
+
}
|
|
170
|
+
catch (e) {
|
|
171
|
+
this.fail('Refresh token revocation failed', e);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (req.authSession)
|
|
175
|
+
await this.sessions.delete(req.authSession.idHash);
|
|
176
|
+
// C1: end the provider session server-side; no end-session hop (§7: no token ever reaches the browser).
|
|
177
|
+
if (req.user)
|
|
178
|
+
await this.revoker.destroyProviderSessions(req.user.id);
|
|
179
|
+
this.auth.clearCookie(res);
|
|
180
|
+
await this.audit.record({
|
|
181
|
+
type: 'logout',
|
|
182
|
+
userId: req.user?.id,
|
|
183
|
+
ip: req.ip,
|
|
184
|
+
userAgent: first(req.headers['user-agent']),
|
|
185
|
+
});
|
|
186
|
+
return { redirectTo: '/admin/login' };
|
|
187
|
+
}
|
|
188
|
+
/** Logs the error name only: messages may echo request data, and nothing token-/cookie-bearing is logged. */
|
|
189
|
+
fail(what, e) {
|
|
190
|
+
this.logger.warn(`${what}: ${e?.name ?? 'Error'}`);
|
|
191
|
+
}
|
|
192
|
+
readLoginState(sealed) {
|
|
193
|
+
if (!sealed)
|
|
194
|
+
return undefined;
|
|
195
|
+
try {
|
|
196
|
+
const v = JSON.parse((0, crypto_1.open)(this.cookieKey, sealed));
|
|
197
|
+
if (typeof v.state !== 'string' || typeof v.nonce !== 'string' || typeof v.verifier !== 'string')
|
|
198
|
+
return undefined;
|
|
199
|
+
return { state: v.state, nonce: v.nonce, verifier: v.verifier, returnTo: (0, return_to_1.sanitizeReturnTo)(v.returnTo) };
|
|
200
|
+
}
|
|
201
|
+
catch {
|
|
202
|
+
return undefined;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
exports.AuthController = AuthController;
|
|
207
|
+
__decorate([
|
|
208
|
+
(0, public_decorator_1.Public)(),
|
|
209
|
+
(0, common_1.Get)('login'),
|
|
210
|
+
__param(0, (0, common_1.Req)()),
|
|
211
|
+
__param(1, (0, common_1.Res)()),
|
|
212
|
+
__metadata("design:type", Function),
|
|
213
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
214
|
+
__metadata("design:returntype", Promise)
|
|
215
|
+
], AuthController.prototype, "login", null);
|
|
216
|
+
__decorate([
|
|
217
|
+
(0, public_decorator_1.Public)(),
|
|
218
|
+
(0, common_1.Get)('callback'),
|
|
219
|
+
__param(0, (0, common_1.Req)()),
|
|
220
|
+
__param(1, (0, common_1.Res)()),
|
|
221
|
+
__metadata("design:type", Function),
|
|
222
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
223
|
+
__metadata("design:returntype", Promise)
|
|
224
|
+
], AuthController.prototype, "callback", null);
|
|
225
|
+
__decorate([
|
|
226
|
+
(0, public_decorator_1.Public)(),
|
|
227
|
+
(0, common_1.Get)('me'),
|
|
228
|
+
__param(0, (0, common_1.Req)()),
|
|
229
|
+
__param(1, (0, common_1.Res)({ passthrough: true })),
|
|
230
|
+
__metadata("design:type", Function),
|
|
231
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
232
|
+
__metadata("design:returntype", Promise)
|
|
233
|
+
], AuthController.prototype, "me", null);
|
|
234
|
+
__decorate([
|
|
235
|
+
(0, common_1.Patch)('me'),
|
|
236
|
+
__param(0, (0, common_1.Req)()),
|
|
237
|
+
__param(1, (0, common_1.Body)()),
|
|
238
|
+
__metadata("design:type", Function),
|
|
239
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
240
|
+
__metadata("design:returntype", Promise)
|
|
241
|
+
], AuthController.prototype, "updateMe", null);
|
|
242
|
+
__decorate([
|
|
243
|
+
(0, common_1.Post)('logout'),
|
|
244
|
+
(0, common_1.HttpCode)(200),
|
|
245
|
+
__param(0, (0, common_1.Req)()),
|
|
246
|
+
__param(1, (0, common_1.Res)({ passthrough: true })),
|
|
247
|
+
__metadata("design:type", Function),
|
|
248
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
249
|
+
__metadata("design:returntype", Promise)
|
|
250
|
+
], AuthController.prototype, "logout", null);
|
|
251
|
+
exports.AuthController = AuthController = __decorate([
|
|
252
|
+
(0, common_1.Controller)('api/auth'),
|
|
253
|
+
__param(0, (0, common_1.Inject)(constants_1.OAUTH2_CONFIG)),
|
|
254
|
+
__param(1, (0, common_1.Inject)(constants_1.AUTH_SETTINGS)),
|
|
255
|
+
__param(2, (0, common_1.Inject)(oidc_client_1.OidcClient)),
|
|
256
|
+
__param(3, (0, common_1.Inject)(session_store_1.SessionStore)),
|
|
257
|
+
__param(4, (0, common_1.Inject)(user_service_1.UserService)),
|
|
258
|
+
__param(5, (0, common_1.Inject)(setup_state_1.SetupState)),
|
|
259
|
+
__param(6, (0, common_1.Inject)(session_auth_service_1.SessionAuthenticator)),
|
|
260
|
+
__param(7, (0, common_1.Inject)(audit_service_1.AuditService)),
|
|
261
|
+
__param(8, (0, common_1.Inject)(constants_1.GRANT_REVOKER)),
|
|
262
|
+
__metadata("design:paramtypes", [Object, Object, oidc_client_1.OidcClient,
|
|
263
|
+
session_store_1.SessionStore,
|
|
264
|
+
user_service_1.UserService,
|
|
265
|
+
setup_state_1.SetupState,
|
|
266
|
+
session_auth_service_1.SessionAuthenticator,
|
|
267
|
+
audit_service_1.AuditService, Object])
|
|
268
|
+
], AuthController);
|
|
269
|
+
//# sourceMappingURL=auth.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.controller.js","sourceRoot":"","sources":["../../src/bff/auth.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,6CAAsD;AACtD,2CAAwG;AACxG,iDAA6D;AAC7D,6BAAwB;AAExB,0DAAsD;AAEtD,4CAAyG;AACzG,sCAAsC;AAEtC,gEAAmD;AACnD,wEAAgG;AAChG,+CAA2D;AAC3D,mDAAiD;AACjD,qDAAyD;AACzD,sDAAkD;AAElD,wDAAuE;AACvE,uCAAuE;AACvE,+CAA2C;AAC3C,mDAA+C;AAE/C,MAAM,iBAAiB,GAAG,WAAW,CAAC;AACtC,MAAM,oBAAoB,GAAG,GAAG,CAAC;AASjC,MAAM,UAAU,GAAG,OAAC,CAAC,MAAM,CAAC;IAC1B,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,IAAI,IAAI,IAAA,iBAAQ,EAAC,CAAC,CAAC,EAAE,EAAE,OAAO,EAAE,oBAAoB,EAAE,CAAC;CAC1G,CAAC,CAAC;AAEH,MAAM,MAAM,GAAG,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
+
export declare function parseCookies(header: string | string[] | undefined): Record<string, string>;
|
|
3
|
+
export interface CookieOptions {
|
|
4
|
+
path: string;
|
|
5
|
+
/** Seconds; 0 deletes the cookie. */
|
|
6
|
+
maxAge: number;
|
|
7
|
+
secure: boolean;
|
|
8
|
+
}
|
|
9
|
+
/** httpOnly + SameSite=Lax always (spec §7). Values are expected to be base64url (no encoding needed). */
|
|
10
|
+
export declare function serializeCookie(name: string, value: string, o: CookieOptions): string;
|
|
11
|
+
export declare const isSecureUrl: (publicUrl: string) => boolean;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isSecureUrl = void 0;
|
|
4
|
+
exports.parseCookies = parseCookies;
|
|
5
|
+
exports.serializeCookie = serializeCookie;
|
|
6
|
+
/** Parses a Cookie request header. The first occurrence of a name wins (most specific path first). */
|
|
7
|
+
function parseCookies(header) {
|
|
8
|
+
const out = {};
|
|
9
|
+
const raw = Array.isArray(header) ? header.join('; ') : header;
|
|
10
|
+
if (!raw)
|
|
11
|
+
return out;
|
|
12
|
+
for (const part of raw.split(';')) {
|
|
13
|
+
const eq = part.indexOf('=');
|
|
14
|
+
if (eq <= 0)
|
|
15
|
+
continue;
|
|
16
|
+
const name = part.slice(0, eq).trim();
|
|
17
|
+
if (!name || name in out)
|
|
18
|
+
continue;
|
|
19
|
+
let value = part.slice(eq + 1).trim();
|
|
20
|
+
if (value.startsWith('"') && value.endsWith('"') && value.length >= 2)
|
|
21
|
+
value = value.slice(1, -1);
|
|
22
|
+
try {
|
|
23
|
+
out[name] = decodeURIComponent(value);
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
out[name] = value;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return out;
|
|
30
|
+
}
|
|
31
|
+
/** httpOnly + SameSite=Lax always (spec §7). Values are expected to be base64url (no encoding needed). */
|
|
32
|
+
function serializeCookie(name, value, o) {
|
|
33
|
+
const parts = [`${name}=${value}`, `Path=${o.path}`, `Max-Age=${Math.max(0, Math.floor(o.maxAge))}`];
|
|
34
|
+
if (o.maxAge <= 0)
|
|
35
|
+
parts.push('Expires=Thu, 01 Jan 1970 00:00:00 GMT');
|
|
36
|
+
parts.push('HttpOnly', 'SameSite=Lax');
|
|
37
|
+
if (o.secure)
|
|
38
|
+
parts.push('Secure');
|
|
39
|
+
return parts.join('; ');
|
|
40
|
+
}
|
|
41
|
+
const isSecureUrl = (publicUrl) => publicUrl.startsWith('https://');
|
|
42
|
+
exports.isSecureUrl = isSecureUrl;
|
|
43
|
+
//# sourceMappingURL=cookies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cookies.js","sourceRoot":"","sources":["../../src/bff/cookies.ts"],"names":[],"mappings":";;;AACA,oCAkBC;AAUD,0CAMC;AAnCD,sGAAsG;AACtG,SAAgB,YAAY,CAAC,MAAqC;IAChE,MAAM,GAAG,GAA2B,EAAE,CAAC;IACvC,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IAC/D,IAAI,CAAC,GAAG;QAAE,OAAO,GAAG,CAAC;IACrB,KAAK,MAAM,IAAI,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;QAClC,MAAM,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAC7B,IAAI,EAAE,IAAI,CAAC;YAAE,SAAS;QACtB,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QACtC,IAAI,CAAC,IAAI,IAAI,IAAI,IAAI,GAAG;YAAE,SAAS;QACnC,IAAI,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,CAA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|
2
|
+
import type { OAuth2Config } from '../config/schema';
|
|
3
|
+
import { type KeyPurpose } from '../security/crypto';
|
|
4
|
+
export type OpenidClientModule = typeof openid;
|
|
5
|
+
/** Tokens as the BFF keeps them. Never sent to the browser. */
|
|
6
|
+
export interface TokenSet {
|
|
7
|
+
accessToken: string;
|
|
8
|
+
refreshToken?: string;
|
|
9
|
+
idToken?: string;
|
|
10
|
+
/** Seconds, from the token response's `expires_in`. */
|
|
11
|
+
expiresIn?: number;
|
|
12
|
+
/** `sub` of the validated ID token (code exchange only). */
|
|
13
|
+
sub?: string;
|
|
14
|
+
/** `amr` of the validated ID token (code exchange only; customer interactions set it, Ruling R2). */
|
|
15
|
+
amr?: string[];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Which confidential client a BFF is. The secret is `deriveKey(OPENCLOUDCMS_SECRET, secretLabel)` as base64url,
|
|
19
|
+
* the same derivation the provider uses for the client's static metadata.
|
|
20
|
+
*/
|
|
21
|
+
export interface OidcClientOptions {
|
|
22
|
+
clientId: string;
|
|
23
|
+
secretLabel: KeyPurpose;
|
|
24
|
+
/** Callback path on the public origin, e.g. `/api/auth/callback`. */
|
|
25
|
+
redirectPath: string;
|
|
26
|
+
scopes: readonly string[];
|
|
27
|
+
}
|
|
28
|
+
/** `opencloudcms-admin` (secret label as `adminClientSecret`). */
|
|
29
|
+
export declare const ADMIN_OIDC_CLIENT: OidcClientOptions;
|
|
30
|
+
/** `opencloudcms-storefront`, the site's customer BFF (secret label as `storefrontClientSecret`). */
|
|
31
|
+
export declare const STOREFRONT_OIDC_CLIENT: OidcClientOptions;
|
|
32
|
+
/** openid-client v6 is ESM-only; loaded like oidc-provider (require on Node 22, else dynamic import). */
|
|
33
|
+
export declare function loadOpenidClient(): Promise<OpenidClientModule>;
|
|
34
|
+
/**
|
|
35
|
+
* Builds the fetch the BFF uses for every call to its own provider (spec §5 internalUrl): a request to the
|
|
36
|
+
* public origin is sent to the internal origin instead, with X-Forwarded-Proto/Host of the public URL, so
|
|
37
|
+
* the provider (proxy=true when https) still computes issuer-relative URLs on the public origin.
|
|
38
|
+
*/
|
|
39
|
+
export declare function internalFetch(publicUrl: string, internalUrl: string, base?: typeof fetch): (url: string, options: openid.CustomFetchOptions) => Promise<Response>;
|
|
40
|
+
/**
|
|
41
|
+
* A BFF as a confidential OIDC client of its own provider (spec D2, §6.3): `opencloudcms-admin` (the default,
|
|
42
|
+
* registered under this class token) or `opencloudcms-storefront` (CUSTOMER_OIDC_CLIENT).
|
|
43
|
+
*/
|
|
44
|
+
export declare class OidcClient {
|
|
45
|
+
private readonly cfg;
|
|
46
|
+
private readonly client;
|
|
47
|
+
private config?;
|
|
48
|
+
constructor(cfg: OAuth2Config, client?: OidcClientOptions);
|
|
49
|
+
get clientId(): string;
|
|
50
|
+
get redirectUri(): string;
|
|
51
|
+
/** Lazy discovery at `${publicUrl}/oauth2`, cached; a failed discovery is retried on the next call. */
|
|
52
|
+
getConfig(): Promise<openid.Configuration>;
|
|
53
|
+
private discover;
|
|
54
|
+
/**
|
|
55
|
+
* Authorization URL as the browser sees it (public origin). Always `prompt=login` (C1): the BFF session
|
|
56
|
+
* is the only authentication a BFF client accepts, so a surviving provider session (of this or the other
|
|
57
|
+
* realm) must never re-authenticate a browser whose BFF session was logged out or expired.
|
|
58
|
+
*/
|
|
59
|
+
buildLoginUrl(p: {
|
|
60
|
+
state: string;
|
|
61
|
+
nonce: string;
|
|
62
|
+
codeChallenge: string;
|
|
63
|
+
loginHint?: string;
|
|
64
|
+
}): Promise<URL>;
|
|
65
|
+
/** `currentUrl` must be the callback URL on the public origin (it doubles as redirect_uri). */
|
|
66
|
+
exchange(currentUrl: URL, p: {
|
|
67
|
+
verifier: string;
|
|
68
|
+
state: string;
|
|
69
|
+
nonce: string;
|
|
70
|
+
}): Promise<TokenSet>;
|
|
71
|
+
refresh(refreshToken: string): Promise<TokenSet>;
|
|
72
|
+
revoke(refreshToken: string): Promise<void>;
|
|
73
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OidcClient = exports.STOREFRONT_OIDC_CLIENT = exports.ADMIN_OIDC_CLIENT = void 0;
|
|
4
|
+
exports.loadOpenidClient = loadOpenidClient;
|
|
5
|
+
exports.internalFetch = internalFetch;
|
|
6
|
+
const constants_1 = require("../constants");
|
|
7
|
+
const provider_factory_1 = require("../provider/provider.factory");
|
|
8
|
+
const crypto_1 = require("../security/crypto");
|
|
9
|
+
/** `opencloudcms-admin` (secret label as `adminClientSecret`). */
|
|
10
|
+
exports.ADMIN_OIDC_CLIENT = {
|
|
11
|
+
clientId: constants_1.ADMIN_CLIENT_ID,
|
|
12
|
+
secretLabel: 'client-secret',
|
|
13
|
+
redirectPath: '/api/auth/callback',
|
|
14
|
+
scopes: provider_factory_1.ADMIN_SCOPES,
|
|
15
|
+
};
|
|
16
|
+
/** `opencloudcms-storefront`, the site's customer BFF (secret label as `storefrontClientSecret`). */
|
|
17
|
+
exports.STOREFRONT_OIDC_CLIENT = {
|
|
18
|
+
clientId: constants_1.STOREFRONT_CLIENT_ID,
|
|
19
|
+
secretLabel: 'client-secret-storefront',
|
|
20
|
+
redirectPath: '/api/customer/auth/callback',
|
|
21
|
+
scopes: constants_1.CUSTOMER_SCOPES,
|
|
22
|
+
};
|
|
23
|
+
let cachedModule;
|
|
24
|
+
// A real dynamic import that tsc (module: commonjs) does not rewrite into require().
|
|
25
|
+
const dynamicImport = new Function('s', 'return import(s)');
|
|
26
|
+
/** openid-client v6 is ESM-only; loaded like oidc-provider (require on Node 22, else dynamic import). */
|
|
27
|
+
async function loadOpenidClient() {
|
|
28
|
+
if (cachedModule)
|
|
29
|
+
return cachedModule;
|
|
30
|
+
let mod;
|
|
31
|
+
try {
|
|
32
|
+
mod = require('openid-client');
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
const code = e.code;
|
|
36
|
+
if (code !== 'ERR_REQUIRE_ESM' && code !== 'ERR_REQUIRE_ASYNC_MODULE')
|
|
37
|
+
throw e;
|
|
38
|
+
mod = await dynamicImport('openid-client');
|
|
39
|
+
}
|
|
40
|
+
cachedModule = mod;
|
|
41
|
+
return cachedModule;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Builds the fetch the BFF uses for every call to its own provider (spec §5 internalUrl): a request to the
|
|
45
|
+
* public origin is sent to the internal origin instead, with X-Forwarded-Proto/Host of the public URL, so
|
|
46
|
+
* the provider (proxy=true when https) still computes issuer-relative URLs on the public origin.
|
|
47
|
+
*/
|
|
48
|
+
function internalFetch(publicUrl, internalUrl, base = fetch) {
|
|
49
|
+
const pub = new URL(publicUrl);
|
|
50
|
+
const internal = new URL(internalUrl);
|
|
51
|
+
return (url, options) => {
|
|
52
|
+
const u = new URL(url);
|
|
53
|
+
if (u.origin !== pub.origin)
|
|
54
|
+
return base(url, options);
|
|
55
|
+
const target = new URL(u.pathname + u.search, internal.origin);
|
|
56
|
+
const headers = {
|
|
57
|
+
...options.headers,
|
|
58
|
+
'x-forwarded-proto': pub.protocol.replace(':', ''),
|
|
59
|
+
'x-forwarded-host': pub.host,
|
|
60
|
+
};
|
|
61
|
+
return base(target, { ...options, headers });
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* A BFF as a confidential OIDC client of its own provider (spec D2, §6.3): `opencloudcms-admin` (the default,
|
|
66
|
+
* registered under this class token) or `opencloudcms-storefront` (CUSTOMER_OIDC_CLIENT).
|
|
67
|
+
*/
|
|
68
|
+
class OidcClient {
|
|
69
|
+
cfg;
|
|
70
|
+
client;
|
|
71
|
+
config;
|
|
72
|
+
constructor(cfg, client = exports.ADMIN_OIDC_CLIENT) {
|
|
73
|
+
this.cfg = cfg;
|
|
74
|
+
this.client = client;
|
|
75
|
+
}
|
|
76
|
+
get clientId() {
|
|
77
|
+
return this.client.clientId;
|
|
78
|
+
}
|
|
79
|
+
get redirectUri() {
|
|
80
|
+
return `${this.cfg.publicUrl}${this.client.redirectPath}`;
|
|
81
|
+
}
|
|
82
|
+
/** Lazy discovery at `${publicUrl}/oauth2`, cached; a failed discovery is retried on the next call. */
|
|
83
|
+
getConfig() {
|
|
84
|
+
if (!this.config) {
|
|
85
|
+
this.config = this.discover().catch((e) => {
|
|
86
|
+
this.config = undefined;
|
|
87
|
+
throw e;
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
return this.config;
|
|
91
|
+
}
|
|
92
|
+
async discover() {
|
|
93
|
+
const client = await loadOpenidClient();
|
|
94
|
+
const insecure = new URL(this.cfg.publicUrl).protocol === 'http:';
|
|
95
|
+
return client.discovery(new URL((0, provider_factory_1.issuerFor)(this.cfg)), this.client.clientId, { redirect_uris: [this.redirectUri], response_types: ['code'], id_token_signed_response_alg: 'ES256' }, client.ClientSecretBasic((0, crypto_1.deriveKey)(this.cfg.secret, this.client.secretLabel).toString('base64url')), {
|
|
96
|
+
// openid-client refuses http issuers unless asked; only for an http publicUrl (dev/tests).
|
|
97
|
+
execute: insecure ? [client.allowInsecureRequests] : [],
|
|
98
|
+
[client.customFetch]: internalFetch(this.cfg.publicUrl, this.cfg.internalUrl),
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Authorization URL as the browser sees it (public origin). Always `prompt=login` (C1): the BFF session
|
|
103
|
+
* is the only authentication a BFF client accepts, so a surviving provider session (of this or the other
|
|
104
|
+
* realm) must never re-authenticate a browser whose BFF session was logged out or expired.
|
|
105
|
+
*/
|
|
106
|
+
async buildLoginUrl(p) {
|
|
107
|
+
const client = await loadOpenidClient();
|
|
108
|
+
const params = {
|
|
109
|
+
redirect_uri: this.redirectUri,
|
|
110
|
+
response_type: 'code',
|
|
111
|
+
scope: this.client.scopes.join(' '),
|
|
112
|
+
state: p.state,
|
|
113
|
+
nonce: p.nonce,
|
|
114
|
+
code_challenge: p.codeChallenge,
|
|
115
|
+
code_challenge_method: 'S256',
|
|
116
|
+
prompt: 'login',
|
|
117
|
+
};
|
|
118
|
+
if (p.loginHint)
|
|
119
|
+
params.login_hint = p.loginHint;
|
|
120
|
+
return client.buildAuthorizationUrl(await this.getConfig(), params);
|
|
121
|
+
}
|
|
122
|
+
/** `currentUrl` must be the callback URL on the public origin (it doubles as redirect_uri). */
|
|
123
|
+
async exchange(currentUrl, p) {
|
|
124
|
+
const client = await loadOpenidClient();
|
|
125
|
+
const res = await client.authorizationCodeGrant(await this.getConfig(), currentUrl, {
|
|
126
|
+
pkceCodeVerifier: p.verifier,
|
|
127
|
+
expectedState: p.state,
|
|
128
|
+
expectedNonce: p.nonce,
|
|
129
|
+
idTokenExpected: true,
|
|
130
|
+
});
|
|
131
|
+
const claims = res.claims();
|
|
132
|
+
const sub = claims?.sub;
|
|
133
|
+
if (!sub)
|
|
134
|
+
throw new Error('ID token without sub');
|
|
135
|
+
const amr = Array.isArray(claims?.amr) ? claims.amr.filter((v) => typeof v === 'string') : undefined;
|
|
136
|
+
return { ...toTokenSet(res), sub, ...(amr ? { amr } : {}) };
|
|
137
|
+
}
|
|
138
|
+
async refresh(refreshToken) {
|
|
139
|
+
const client = await loadOpenidClient();
|
|
140
|
+
return toTokenSet(await client.refreshTokenGrant(await this.getConfig(), refreshToken));
|
|
141
|
+
}
|
|
142
|
+
async revoke(refreshToken) {
|
|
143
|
+
const client = await loadOpenidClient();
|
|
144
|
+
await client.tokenRevocation(await this.getConfig(), refreshToken, { token_type_hint: 'refresh_token' });
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
exports.OidcClient = OidcClient;
|
|
148
|
+
function toTokenSet(res) {
|
|
149
|
+
if (!res.access_token)
|
|
150
|
+
throw new Error('token response without access_token');
|
|
151
|
+
return {
|
|
152
|
+
accessToken: res.access_token,
|
|
153
|
+
refreshToken: res.refresh_token,
|
|
154
|
+
idToken: res.id_token,
|
|
155
|
+
expiresIn: typeof res.expires_in === 'number' ? res.expires_in : undefined,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=oidc-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oidc-client.js","sourceRoot":"","sources":["../../src/bff/oidc-client.ts"],"names":[],"mappings":";;;AAsDA,4CAYC;AAOD,sCAkBC;AAzFD,4CAAsF;AACtF,mEAAuE;AACvE,+CAAgE;AA6BhE,kEAAkE;AACrD,QAAA,iBAAiB,GAAsB;IAClD,QAAQ,EAAE,2BAAe;IACzB,WAAW,EAAE,eAAe;IAC5B,YAAY,EAAE,oBAAoB;IAClC,MAAM,EAAE,+BAAY;CACrB,CAAC;AAEF,qGAAqG;AACxF,QAAA,sBAAsB,GAAsB;IACvD,QAAQ,EAAE,gCAAoB;IAC9B,WAAW,EAAE,0BAA0B;IACvC,YAAY,EAAE,6BAA6B;IAC3C,MAAM,EAAE,2BAAe;CACxB,CAAC;AAEF,IAAI,YAA4C,CAAC;AACjD,qFAAqF;AACrF,MAAM,aAAa,GAAG,IAAI,QAAQ,CAAC,GAAG,EAAE,kBAAkB,CAAgC,CAAC;AAE3F,yGAAyG;AAClG,KAAK,UAAU,gBAAgB;IACpC,IAAI,YAAY;QAAE,OAAO,YAAY,CAAC;IACtC,IAAI,GAAQ,CAAC;IACb,IAAI,CAAC;QACH,GAAG,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IACjC,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,IAAI,GAAI,CAAuB,CAAC,IAAI,CAAC;QAC3C,IAAI,IAAI,KAAK,iBAAiB,IAAI,IAAI,KAAK,0BAA0B;YAAE,MAAM,CAAC,CAAC;QAC/E,GAAG,GAAG,MAAM,aAAa,CAAC,eAAe,CAAC,CAAC;IAC7C,CAAC;IACD,YAAY,GAAG,GAAyB,CAAC;IACzC,OAAO,YAAY,CAAC;AACtB,CAAC;AAED;;;;GAIG;AACH,SAAgB,aAAa,CAC3B,SAAiB,EACjB,WAAmB,EACnB,OAAqB,KAA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AAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAClH,OAAO,EAAE,GAAG,UAAU,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;IAC9D,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,YAAoB;QAChC,MAAM,MAAM,GAAG,MAAM,gBAAgB,EAAE,CAAC;QACxC,OAAO,UAAU,CAAC,MAAM,MAAM,CAAC,iBAAiB,CAAC,MAAM,IAAI,CAAC,SAAS,EAAE,EAAE,YAAY,CAAC,CAAC,CAAC;IAC1F,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,YAAoB;QAC/B,MAAM,MAAM,GAAG,MAAM,gBAAgB,EAAE,CAAC;QACxC,MAAM,MAAM,CAAC,eAAe,CAAC,MAAM,IAAI,CAAC,SAAS,EAAE,EAAE,YAAY,EAAE,EAAE,eAAe,EAAE,eAAe,EAAE,CAAC,CAAC;IAC3G,CAAC;CACF;AAzFD,gCAyFC;AAED,SAAS,UAAU,CAAC,GAAiC;IACnD,IAAI,CAAC,GAAG,CAAC,YAAY;QAAE,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;IAC9E,OAAO;QACL,WAAW,EAAE,GAAG,CAAC,YAAY;QAC7B,YAAY,EAAE,GAAG,CAAC,aAAa;QAC/B,OAAO,EAAE,GAAG,CAAC,QAAQ;QACrB,SAAS,EAAE,OAAO,GAAG,CAAC,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS;KAC3E,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { OidcClient } from './oidc-client';
|
|
2
|
+
import { type SessionRow, type SessionStore } from './session.store';
|
|
3
|
+
/** Refresh when the access token has less than this left (spec §6.5 step 4). */
|
|
4
|
+
export declare const REFRESH_MARGIN_MS = 60000;
|
|
5
|
+
/**
|
|
6
|
+
* Access-token refresh of a BFF session (admin or customer store, with that realm's OidcClient).
|
|
7
|
+
*
|
|
8
|
+
* In-process single-flight per session in front of the DB lease (R18): concurrent requests of one
|
|
9
|
+
* session await the same refresh. No DB connection or transaction is held while the HTTP call to
|
|
10
|
+
* /oauth2/token runs (that endpoint needs the same pool).
|
|
11
|
+
*/
|
|
12
|
+
export declare class SessionRefresher {
|
|
13
|
+
private readonly sessions;
|
|
14
|
+
private readonly oidc;
|
|
15
|
+
private readonly logger;
|
|
16
|
+
private readonly refreshing;
|
|
17
|
+
constructor(sessions: SessionStore, oidc: OidcClient);
|
|
18
|
+
/** True when the session's access token is within REFRESH_MARGIN_MS of expiry (or past it). */
|
|
19
|
+
needsRefresh(session: SessionRow, now?: number): boolean;
|
|
20
|
+
/** False when the session vanished or the refresh failed or timed out (the caller destroys the session). */
|
|
21
|
+
refresh(read: SessionRow): Promise<boolean>;
|
|
22
|
+
private refreshLeased;
|
|
23
|
+
/** Loser of the lease: poll until the holder has stored newer tokens (→ reuse) or give up. */
|
|
24
|
+
private awaitOtherRefresh;
|
|
25
|
+
/** Error name only: messages may carry token-endpoint responses. */
|
|
26
|
+
private warn;
|
|
27
|
+
}
|