fase(25-26): keyboard shortcuts, mobile responsive, enterprise SSO/audit
- Phase 25.4: N shortcut for new exploration on dashboard (react-hotkeys-hook) - Phase 25.5: overflow-x-auto on tables, responsive padding (p-4 md:p-6) - Phase 26: SAML/OIDC/LDAP providers (build-fixed), TOTP/MFA service - Phase 26: KyselySSOConfigRepository + KyselyTOTPRepository - Phase 26: SSO HTTP controller (config CRUD + MFA setup/verify/disable) - Phase 26: Audit module index.ts + SSO module index.ts - Phase 26: Session management endpoints (findByUserId, deleteById, list/revoke) - Phase 26: SSO and audit routes feature-gated (auth:sso, audit:logs) - Phase 26: Frontend SSOSection (SAML/OIDC/LDAP config + TOTP setup) - Phase 26: Frontend SessionsSection (list/revoke active sessions) - Phase 26: Settings navigation updated with SSO & Sessions sections Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
81
dist/modules/sso/infrastructure/providers/LDAPProvider.js
vendored
Normal file
81
dist/modules/sso/infrastructure/providers/LDAPProvider.js
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.LDAPProvider = void 0;
|
||||
/**
|
||||
* LDAP/Active Directory authentication provider.
|
||||
*/
|
||||
const ldapjs_1 = __importDefault(require("ldapjs"));
|
||||
class LDAPProvider {
|
||||
constructor(config) {
|
||||
this.config = config;
|
||||
}
|
||||
async authenticate(username, password) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const client = ldapjs_1.default.createClient({
|
||||
url: this.config.url,
|
||||
tlsOptions: this.config.tlsOptions,
|
||||
});
|
||||
client.on('error', (err) => {
|
||||
reject(err);
|
||||
});
|
||||
const escaped = username.replace(/[\\*()\x00]/g, (c) => `\\${c.charCodeAt(0).toString(16).padStart(2, '0')}`);
|
||||
const filter = (this.config.userSearchFilter ?? '(uid={username})')
|
||||
.replace('{username}', escaped);
|
||||
// Bind with service account if provided
|
||||
const bindDN = this.config.bindDN ?? '';
|
||||
const bindPwd = this.config.bindPassword ?? '';
|
||||
client.bind(bindDN, bindPwd, (err) => {
|
||||
if (err) {
|
||||
client.destroy();
|
||||
return resolve(null);
|
||||
}
|
||||
client.search(this.config.baseDN, { filter, scope: 'sub', attributes: ['dn', 'mail', 'displayName', 'memberOf'] }, (searchErr, res) => {
|
||||
if (searchErr) {
|
||||
client.destroy();
|
||||
return reject(searchErr);
|
||||
}
|
||||
let foundEntry = null;
|
||||
res.on('searchEntry', (entry) => {
|
||||
foundEntry = entry;
|
||||
});
|
||||
res.on('error', (resErr) => {
|
||||
client.destroy();
|
||||
reject(resErr);
|
||||
});
|
||||
res.on('end', () => {
|
||||
if (!foundEntry) {
|
||||
client.destroy();
|
||||
return resolve(null);
|
||||
}
|
||||
const entry = foundEntry;
|
||||
const userDN = entry.objectName ?? '';
|
||||
// Authenticate as the found user
|
||||
client.bind(userDN, password, (authErr) => {
|
||||
client.destroy();
|
||||
if (authErr) {
|
||||
return resolve(null);
|
||||
}
|
||||
const obj = entry.pojo;
|
||||
const getAttr = (name) => {
|
||||
const attr = obj.attributes.find((a) => a.type === name);
|
||||
return attr?.values[0];
|
||||
};
|
||||
resolve({
|
||||
dn: userDN,
|
||||
email: getAttr('mail'),
|
||||
displayName: getAttr('displayName'),
|
||||
groups: obj.attributes
|
||||
.find((a) => a.type === 'memberOf')
|
||||
?.values ?? [],
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.LDAPProvider = LDAPProvider;
|
||||
45
dist/modules/sso/infrastructure/providers/OIDCProvider.js
vendored
Normal file
45
dist/modules/sso/infrastructure/providers/OIDCProvider.js
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.OIDCProvider = void 0;
|
||||
/**
|
||||
* OIDC (OpenID Connect) SSO provider.
|
||||
* Supports Okta, Azure AD, Google Workspace.
|
||||
*/
|
||||
const openid_client_1 = require("openid-client");
|
||||
class OIDCProvider {
|
||||
constructor(config) {
|
||||
this.config = config;
|
||||
}
|
||||
async generateAuthUrl() {
|
||||
const issuerUrl = new URL(this.config.issuer);
|
||||
const oidcConfig = await (0, openid_client_1.discovery)(issuerUrl, this.config.clientId, this.config.clientSecret);
|
||||
const state = (0, openid_client_1.randomState)();
|
||||
const params = new URLSearchParams({
|
||||
client_id: this.config.clientId,
|
||||
redirect_uri: this.config.redirectUri,
|
||||
response_type: 'code',
|
||||
scope: (this.config.scopes ?? ['openid', 'email', 'profile']).join(' '),
|
||||
state,
|
||||
});
|
||||
const url = (0, openid_client_1.buildAuthorizationUrl)(oidcConfig, params);
|
||||
return { url: url.href, state, codeVerifier: '' };
|
||||
}
|
||||
async handleCallback(params, expectedState, _codeVerifier) {
|
||||
const issuerUrl = new URL(this.config.issuer);
|
||||
const oidcConfig = await (0, openid_client_1.discovery)(issuerUrl, this.config.clientId, this.config.clientSecret);
|
||||
const currentUrl = new URL(`${this.config.redirectUri}?${params.toString()}`);
|
||||
const tokens = await (0, openid_client_1.authorizationCodeGrant)(oidcConfig, currentUrl, {
|
||||
expectedState,
|
||||
});
|
||||
const claims = tokens.claims();
|
||||
if (!claims) {
|
||||
throw new Error('OIDC: no claims in token response');
|
||||
}
|
||||
return {
|
||||
sub: String(claims['sub'] ?? ''),
|
||||
email: typeof claims['email'] === 'string' ? claims['email'] : undefined,
|
||||
name: typeof claims['name'] === 'string' ? claims['name'] : undefined,
|
||||
};
|
||||
}
|
||||
}
|
||||
exports.OIDCProvider = OIDCProvider;
|
||||
35
dist/modules/sso/infrastructure/providers/SAMLProvider.js
vendored
Normal file
35
dist/modules/sso/infrastructure/providers/SAMLProvider.js
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.SAMLProvider = void 0;
|
||||
/**
|
||||
* SAML 2.0 SSO provider.
|
||||
* Uses @node-saml/node-saml for SP-initiated SSO.
|
||||
*/
|
||||
const node_saml_1 = require("@node-saml/node-saml");
|
||||
class SAMLProvider {
|
||||
constructor(config) {
|
||||
const samlConfig = {
|
||||
entryPoint: config.entryPoint,
|
||||
issuer: config.issuer,
|
||||
idpCert: config.cert,
|
||||
callbackUrl: config.callbackUrl,
|
||||
wantAuthnResponseSigned: false,
|
||||
};
|
||||
this.saml = new node_saml_1.SAML(samlConfig);
|
||||
}
|
||||
async generateAuthUrl(relayState) {
|
||||
return this.saml.getAuthorizeUrlAsync(relayState ?? '', undefined, {});
|
||||
}
|
||||
async validateResponse(body) {
|
||||
const { profile } = await this.saml.validatePostResponseAsync(body);
|
||||
if (!profile) {
|
||||
throw new Error('SAML validation failed: no profile');
|
||||
}
|
||||
return {
|
||||
nameID: typeof profile.nameID === 'string' ? profile.nameID : '',
|
||||
email: typeof profile['email'] === 'string' ? profile['email'] : undefined,
|
||||
displayName: typeof profile.displayName === 'string' ? profile.displayName : undefined,
|
||||
};
|
||||
}
|
||||
}
|
||||
exports.SAMLProvider = SAMLProvider;
|
||||
39
dist/modules/sso/infrastructure/providers/TOTPService.js
vendored
Normal file
39
dist/modules/sso/infrastructure/providers/TOTPService.js
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.TOTPService = void 0;
|
||||
/**
|
||||
* TOTP (Time-based One-Time Password) service.
|
||||
* Uses otpauth library for RFC 6238 compliant TOTP.
|
||||
*/
|
||||
const otpauth_1 = require("otpauth");
|
||||
class TOTPService {
|
||||
constructor(issuer = 'ABE') {
|
||||
this.issuer = issuer;
|
||||
}
|
||||
generateSecret(userId, label) {
|
||||
const totp = new otpauth_1.TOTP({
|
||||
issuer: this.issuer,
|
||||
label,
|
||||
algorithm: 'SHA1',
|
||||
digits: 6,
|
||||
period: 30,
|
||||
secret: new otpauth_1.Secret({ size: 20 }),
|
||||
});
|
||||
return {
|
||||
secret: totp.secret.base32,
|
||||
otpauthUrl: totp.toString(),
|
||||
};
|
||||
}
|
||||
verify(secret, token) {
|
||||
const totp = new otpauth_1.TOTP({
|
||||
issuer: this.issuer,
|
||||
algorithm: 'SHA1',
|
||||
digits: 6,
|
||||
period: 30,
|
||||
secret: otpauth_1.Secret.fromBase32(secret),
|
||||
});
|
||||
const delta = totp.validate({ token, window: 1 });
|
||||
return delta !== null;
|
||||
}
|
||||
}
|
||||
exports.TOTPService = TOTPService;
|
||||
Reference in New Issue
Block a user