From 4eae9dd608aaf0eeb6d62daf735400f8973b5ff2 Mon Sep 17 00:00:00 2001 From: "Pavel.Samusev" Date: Tue, 24 Sep 2024 16:31:55 +0300 Subject: [PATCH] [Feat][GRAFX-3749] Allow specify some authentication config in a connector definition (#67) --- scripts/publish.js | 11 ++-- .../resources/schemas/connector-config.json | 51 +++++++++++++++++ src/connector-cli/src/core/types/gen-types.ts | 55 +++++++++++++++++-- src/connectors/acquia/package.json | 18 +++++- 4 files changed, 123 insertions(+), 12 deletions(-) diff --git a/scripts/publish.js b/scripts/publish.js index 84037cf..9f74443 100644 --- a/scripts/publish.js +++ b/scripts/publish.js @@ -1,6 +1,6 @@ const fs = require('fs'); const path = require('path'); -const {execSync} = require('child_process'); +const { execSync } = require('child_process'); /* This script is used to build and publish the connectors to the "publish" folder. @@ -98,10 +98,10 @@ function processConnector(dir) { // Read the package.json and extract the necessary info const packageJson = require(path.join(dir, 'package.json')); - const {name, description, version, author } = packageJson; + const { name, description, version, author } = packageJson; // Read the connector.js file - const {connectorJs} = readScripts(outDir, dir); + const { connectorJs } = readScripts(outDir, dir); // Build the project const connectorInfo = extractConnectorInfo(outDir, dir); @@ -113,7 +113,8 @@ function processConnector(dir) { description, version, author, - script: connectorJs + script: connectorJs, + authenticationConfig: packageJson.config.authenticationConfig }; Object.assign(jsonObject, connectorInfo); @@ -158,5 +159,5 @@ function readScripts(outDir, dir) { const connectorTs = fs.existsSync(path.join(dir, 'connector.ts')) ? fs.readFileSync(path.join(dir, 'connector.ts'), 'utf-8') : undefined; - return {connectorJs, connectorTs}; + return { connectorJs, connectorTs }; } \ No newline at end of file diff --git a/src/connector-cli/resources/schemas/connector-config.json b/src/connector-cli/resources/schemas/connector-config.json index 6695140..256c32e 100644 --- a/src/connector-cli/resources/schemas/connector-config.json +++ b/src/connector-cli/resources/schemas/connector-config.json @@ -28,6 +28,57 @@ ] } }, + "authenticationConfig": { + "type": "object", + "properties": { + "oAuth2ResourceOwnerPassword": { + "type": "object", + "properties": { + "bodyFormat": { + "type": "string", + "enum": ["applicationJson", "formUrlEncoded"] + } + }, + "required": ["bodyFormat"], + "additionalProperties": false + }, + "oAuth2AuthorizationCode": { + "type": "object", + "properties": { + "authorizationServerMetadata": { + "type": "object", + "properties": { + "token_endpoint_auth_methods_supported": { + "type": "array", + "items": { + "type": "string", + "enum": ["client_secret_basic", "client_secret_post"] + } + } + }, + "required": ["token_endpoint_auth_methods_supported"], + "additionalProperties": false + }, + "specCustomization": { + "type": "object", + "properties": { + "requestContentType": { + "type": "string", + "enum": ["applicationJson", "formUrlEncoded"] + }, + "codeParameterName": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "required": ["authorizationServerMetadata"], + "additionalProperties": false + } + }, + "additionalProperties": false + }, "mappings": { "type": "object" } diff --git a/src/connector-cli/src/core/types/gen-types.ts b/src/connector-cli/src/core/types/gen-types.ts index 0980f62..36bf2db 100644 --- a/src/connector-cli/src/core/types/gen-types.ts +++ b/src/connector-cli/src/core/types/gen-types.ts @@ -72,12 +72,36 @@ export interface StaticKey { } export interface ConnectorConfig { - connectorName?: string; - iconUrl?: string; - mappings?: { [key: string]: any }; - options: { [key: string]: any }; - supportedAuth: SupportedAuth[]; - type: Type; + authenticationConfig?: AuthenticationConfig; + connectorName?: string; + iconUrl?: string; + mappings?: { [key: string]: any }; + options: { [key: string]: any }; + supportedAuth: SupportedAuth[]; + type: Type; +} + +export interface AuthenticationConfig { + oAuth2AuthorizationCode?: OAuth2AuthorizationCode; + oAuth2ResourceOwnerPassword?: OAuth2ResourceOwnerPassword; +} + +export interface OAuth2AuthorizationCode { + authorizationServerMetadata: OAuth2AuthorizationCodeAuthorizationServerMetadata; + specCustomization?: OAuth2AuthorizationCodeSpecCustomization; +} + +export interface OAuth2AuthorizationCodeAuthorizationServerMetadata { + token_endpoint_auth_methods_supported: TokenEndpointAuthMethodsSupported[]; +} + +export interface OAuth2AuthorizationCodeSpecCustomization { + codeParameterName?: string; + requestContentType?: RequestContentType; +} + +export interface OAuth2ResourceOwnerPassword { + bodyFormat: RequestContentType; } export enum SupportedAuth { @@ -340,6 +364,7 @@ const typeMap: any = { { json: "value", js: "value", typ: "" }, ], false), "ConnectorConfig": o([ + { json: "authenticationConfig", js: "authenticationConfig", typ: u(undefined, r("AuthenticationConfig")) }, { json: "connectorName", js: "connectorName", typ: u(undefined, "") }, { json: "iconUrl", js: "iconUrl", typ: u(undefined, "") }, { json: "mappings", js: "mappings", typ: u(undefined, m("any")) }, @@ -347,6 +372,24 @@ const typeMap: any = { { json: "supportedAuth", js: "supportedAuth", typ: a(r("SupportedAuth")) }, { json: "type", js: "type", typ: r("Type") }, ], false), + "AuthenticationConfig": o([ + { json: "oAuth2AuthorizationCode", js: "oAuth2AuthorizationCode", typ: u(undefined, r("OAuth2AuthorizationCode")) }, + { json: "oAuth2ResourceOwnerPassword", js: "oAuth2ResourceOwnerPassword", typ: u(undefined, r("OAuth2ResourceOwnerPassword")) }, + ], false), + "OAuth2AuthorizationCode": o([ + { json: "authorizationServerMetadata", js: "authorizationServerMetadata", typ: r("OAuth2AuthorizationCodeAuthorizationServerMetadata") }, + { json: "specCustomization", js: "specCustomization", typ: u(undefined, r("OAuth2AuthorizationCodeSpecCustomization")) }, + ], false), + "OAuth2AuthorizationCodeAuthorizationServerMetadata": o([ + { json: "token_endpoint_auth_methods_supported", js: "token_endpoint_auth_methods_supported", typ: a(r("TokenEndpointAuthMethodsSupported")) }, + ], false), + "OAuth2AuthorizationCodeSpecCustomization": o([ + { json: "codeParameterName", js: "codeParameterName", typ: u(undefined, "") }, + { json: "requestContentType", js: "requestContentType", typ: u(undefined, r("RequestContentType")) }, + ], false), + "OAuth2ResourceOwnerPassword": o([ + { json: "bodyFormat", js: "bodyFormat", typ: r("RequestContentType") }, + ], false), "TokenEndpointAuthMethodsSupported": [ "client_secret_basic", "client_secret_post", diff --git a/src/connectors/acquia/package.json b/src/connectors/acquia/package.json index 6a6884c..94ab84b 100644 --- a/src/connectors/acquia/package.json +++ b/src/connectors/acquia/package.json @@ -1,7 +1,7 @@ { "name": "acquia", "description": "Acquia DAM", - "version": "1.0.10", + "version": "1.0.11", "author": { "name": "CHILI publish", "email": "info@chili-publish.com", @@ -20,6 +20,22 @@ "oAuth2AuthorizationCode", "staticKey" ], + "authenticationConfig": { + "oAuth2ResourceOwnerPassword": { + "bodyFormat": "applicationJson" + }, + "oAuth2AuthorizationCode": { + "authorizationServerMetadata": { + "token_endpoint_auth_methods_supported": [ + "client_secret_post" + ] + }, + "specCustomization": { + "requestContentType": "applicationJson", + "codeParameterName": "authorization_code" + } + } + }, "mappings": {} }, "private": true,