@kwirthmagnify/kwirth-common-back 0.5.15 → 0.5.17

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.
@@ -0,0 +1,44 @@
1
+ export declare enum EIdpConnectorKind {
2
+ OIDC = "oidc",
3
+ OAUTH2 = "oauth2"
4
+ }
5
+ export type IdpFieldType = 'text' | 'number' | 'boolean' | 'password';
6
+ export interface IIdpConfigFieldDef {
7
+ name: string;
8
+ label: string;
9
+ type?: IdpFieldType;
10
+ required?: boolean;
11
+ options?: string[];
12
+ }
13
+ export interface IIdpIdentity {
14
+ email: string;
15
+ emailVerified: boolean;
16
+ name?: string;
17
+ sub?: string;
18
+ }
19
+ export interface IIdpAuthContext {
20
+ redirectUri: string;
21
+ state: string;
22
+ codeChallenge: string;
23
+ }
24
+ export interface IIdpCallbackContext {
25
+ code: string;
26
+ codeVerifier: string;
27
+ redirectUri: string;
28
+ }
29
+ export interface IIdpConnector {
30
+ connectorId: string;
31
+ label: string;
32
+ kind: EIdpConnectorKind;
33
+ getConfigSchema(): IIdpConfigFieldDef[];
34
+ buildAuthorizationUrl(config: Record<string, unknown>, ctx: IIdpAuthContext): Promise<string> | string;
35
+ handleCallback(config: Record<string, unknown>, ctx: IIdpCallbackContext): Promise<IIdpIdentity>;
36
+ }
37
+ export interface IIdpInstanceConfig {
38
+ id: string;
39
+ connectorId: string;
40
+ label: string;
41
+ enabled: boolean;
42
+ config: Record<string, unknown>;
43
+ }
44
+ export type TIdpConnectorConstructor = new () => IIdpConnector;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ /*
3
+ Interfaz de conector de Identity Provider (IdP) para Kwirth.
4
+
5
+ Un conector es LOGICA PURA (sin rutas propias): construye la URL de autorizacion del IdP
6
+ y procesa el callback devolviendo la identidad verificada. El flujo HTTP pre-login y la
7
+ emision de AccessKey viven en el core de Kwirth, nunca en el conector.
8
+
9
+ Vive en common-back para que los conectores empaquetados por separado (idps/<id>/) puedan
10
+ implementarlo importando '@kwirthmagnify/kwirth-common-back', igual que ISender/IProvider.
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.EIdpConnectorKind = void 0;
14
+ var EIdpConnectorKind;
15
+ (function (EIdpConnectorKind) {
16
+ EIdpConnectorKind["OIDC"] = "oidc";
17
+ EIdpConnectorKind["OAUTH2"] = "oauth2";
18
+ })(EIdpConnectorKind || (exports.EIdpConnectorKind = EIdpConnectorKind = {}));
@@ -17,6 +17,7 @@ export interface IProvider {
17
17
  addSubscriber(c: IProviderSubscriber, data: any): Promise<void>;
18
18
  removeSubscriber(c: IProviderSubscriber): Promise<void>;
19
19
  updateSubscription?(c: IProviderSubscriber, data: any): Promise<void>;
20
+ configure?(config: Record<string, unknown>): void;
20
21
  startProvider(): Promise<void>;
21
22
  stopProvider(): Promise<void>;
22
23
  router: any;
package/dist/index.d.ts CHANGED
@@ -2,5 +2,7 @@ export * from './IChannel';
2
2
  export * from './IDaemon';
3
3
  export * from './IProvider';
4
4
  export * from './ISender';
5
+ export * from './IIdpConnector';
6
+ export * from './oidc';
5
7
  export * from './KubernetesTools';
6
8
  export * from '@kwirthmagnify/kwirth-common';
package/dist/index.js CHANGED
@@ -18,5 +18,7 @@ __exportStar(require("./IChannel"), exports);
18
18
  __exportStar(require("./IDaemon"), exports);
19
19
  __exportStar(require("./IProvider"), exports);
20
20
  __exportStar(require("./ISender"), exports);
21
+ __exportStar(require("./IIdpConnector"), exports);
22
+ __exportStar(require("./oidc"), exports);
21
23
  __exportStar(require("./KubernetesTools"), exports);
22
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,57 @@
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
+ const tokenSet = await client.callback(ctx.redirectUri, { code: ctx.code }, { code_verifier: ctx.codeVerifier });
50
+ const claims = tokenSet.claims();
51
+ return {
52
+ email: String(claims.email ?? ''),
53
+ emailVerified: claims.email_verified === true,
54
+ name: claims.name ? String(claims.name) : undefined,
55
+ sub: claims.sub
56
+ };
57
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kwirthmagnify/kwirth-common-back",
3
- "version": "0.5.15",
3
+ "version": "0.5.17",
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",