@kwirthmagnify/kwirth-common-back 0.5.16 → 0.5.18
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/dist/IIdpConnector.d.ts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/oidc.d.ts +4 -0
- package/dist/oidc.js +63 -0
- package/package.json +3 -2
package/dist/IIdpConnector.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -19,5 +19,6 @@ __exportStar(require("./IDaemon"), exports);
|
|
|
19
19
|
__exportStar(require("./IProvider"), exports);
|
|
20
20
|
__exportStar(require("./ISender"), exports);
|
|
21
21
|
__exportStar(require("./IIdpConnector"), exports);
|
|
22
|
+
__exportStar(require("./oidc"), exports);
|
|
22
23
|
__exportStar(require("./KubernetesTools"), exports);
|
|
23
24
|
__exportStar(require("@kwirthmagnify/kwirth-common"), exports);
|
package/dist/oidc.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { IIdpAuthContext, IIdpCallbackContext, IIdpConfigFieldDef, IIdpIdentity } from './IIdpConnector';
|
|
2
|
+
export declare function oidcConfigSchema(): IIdpConfigFieldDef[];
|
|
3
|
+
export declare function oidcBuildAuthorizationUrl(config: Record<string, unknown>, ctx: IIdpAuthContext, defaultIssuer?: string): Promise<string>;
|
|
4
|
+
export declare function oidcHandleCallback(config: Record<string, unknown>, ctx: IIdpCallbackContext, defaultIssuer?: string): Promise<IIdpIdentity>;
|
package/dist/oidc.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.oidcConfigSchema = oidcConfigSchema;
|
|
4
|
+
exports.oidcBuildAuthorizationUrl = oidcBuildAuthorizationUrl;
|
|
5
|
+
exports.oidcHandleCallback = oidcHandleCallback;
|
|
6
|
+
const openid_client_1 = require("openid-client");
|
|
7
|
+
/*
|
|
8
|
+
Lógica OIDC compartida por todos los conectores OIDC (Google, Keycloak, GitLab, Microsoft, ...).
|
|
9
|
+
Vive en common-back y el back la expone como global (__kwirth_back__.kwirthCommonBack), de modo
|
|
10
|
+
que los conectores la usan por composición SIN bundlear openid-client ni duplicar el flujo.
|
|
11
|
+
|
|
12
|
+
Flujo Authorization Code + PKCE con intercambio back-channel (el id_token llega por TLS del
|
|
13
|
+
token endpoint, así que openid-client valida issuer/aud y basta con eso).
|
|
14
|
+
*/
|
|
15
|
+
// esquema de config estándar de un IdP OIDC (clientSecret es 'password' → se enmascara en la UI)
|
|
16
|
+
function oidcConfigSchema() {
|
|
17
|
+
return [
|
|
18
|
+
{ name: 'clientId', label: 'Client ID', type: 'text', required: true },
|
|
19
|
+
{ name: 'clientSecret', label: 'Client Secret', type: 'password', required: true },
|
|
20
|
+
{ name: 'scopes', label: 'Scopes', type: 'text' },
|
|
21
|
+
{ name: 'issuer', label: 'Issuer URL', type: 'text' }
|
|
22
|
+
];
|
|
23
|
+
}
|
|
24
|
+
async function makeClient(config, redirectUri, defaultIssuer) {
|
|
25
|
+
const issuerUrl = config.issuer || defaultIssuer;
|
|
26
|
+
if (!issuerUrl)
|
|
27
|
+
throw new Error('OIDC issuer not configured');
|
|
28
|
+
const issuer = await openid_client_1.Issuer.discover(issuerUrl);
|
|
29
|
+
return new issuer.Client({
|
|
30
|
+
client_id: config.clientId,
|
|
31
|
+
client_secret: config.clientSecret,
|
|
32
|
+
redirect_uris: [redirectUri],
|
|
33
|
+
response_types: ['code']
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
async function oidcBuildAuthorizationUrl(config, ctx, defaultIssuer) {
|
|
37
|
+
const client = await makeClient(config, ctx.redirectUri, defaultIssuer);
|
|
38
|
+
const scope = config.scopes || 'openid email profile';
|
|
39
|
+
return client.authorizationUrl({
|
|
40
|
+
scope,
|
|
41
|
+
state: ctx.state,
|
|
42
|
+
redirect_uri: ctx.redirectUri,
|
|
43
|
+
code_challenge: ctx.codeChallenge,
|
|
44
|
+
code_challenge_method: 'S256'
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
async function oidcHandleCallback(config, ctx, defaultIssuer) {
|
|
48
|
+
const client = await makeClient(config, ctx.redirectUri, defaultIssuer);
|
|
49
|
+
// pasamos los params crudos del callback (incluyen iss para RFC 9207 y state); el state ya lo
|
|
50
|
+
// valida el core, pero openid-client exige checks.state si el param state viene presente.
|
|
51
|
+
const params = ctx.params ?? { code: ctx.code };
|
|
52
|
+
const checks = { code_verifier: ctx.codeVerifier };
|
|
53
|
+
if (params.state !== undefined)
|
|
54
|
+
checks.state = params.state;
|
|
55
|
+
const tokenSet = await client.callback(ctx.redirectUri, params, checks);
|
|
56
|
+
const claims = tokenSet.claims();
|
|
57
|
+
return {
|
|
58
|
+
email: String(claims.email ?? ''),
|
|
59
|
+
emailVerified: claims.email_verified === true,
|
|
60
|
+
name: claims.name ? String(claims.name) : undefined,
|
|
61
|
+
sub: claims.sub
|
|
62
|
+
};
|
|
63
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kwirthmagnify/kwirth-common-back",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.18",
|
|
4
4
|
"description": "Backend interfaces for building Kwirth provider and channel plugins",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsc"
|
|
@@ -27,7 +27,8 @@
|
|
|
27
27
|
"@kubernetes/client-node": "^1.4.0",
|
|
28
28
|
"@kwirthmagnify/kwirth-common": "^0.5.14",
|
|
29
29
|
"express": "^4.18.0",
|
|
30
|
-
"js-yaml": "^4.1.0"
|
|
30
|
+
"js-yaml": "^4.1.0",
|
|
31
|
+
"openid-client": "^5.7.0"
|
|
31
32
|
},
|
|
32
33
|
"devDependencies": {
|
|
33
34
|
"@types/express": "^4.17.21",
|