Skip to content

Commit d63524c

Browse files
Injecting and passing authProvider and authToken variables to execute sonataflow (#509)
* [FLPATH-2143] : initial commit to pass the auth header token to sonataflow * [FLPATH-2143] : pushing failed changes * [FLPATH-2143] : enabling to send auht tokens in req body instead of headers * [FLPATH-2143] : enabling to send auht tokens in req body instead of headers * [FLPATH-2143] : enabling to send auht tokens in req body instead of headers * [FLPATH-2143] : enabling to send auht tokens in req body instead of headers * Update workspaces/orchestrator/plugins/orchestrator-backend/src/service/SonataFlowService.ts Co-authored-by: Marek Libra <marek.libra@gmail.com> * [FLPATH-2143] : enabling to send auht tokens in req body instead of headers * Update workspaces/orchestrator/plugins/orchestrator-backend/src/service/SonataFlowService.ts Co-authored-by: Marek Libra <marek.libra@gmail.com> * [FLPATH-2143] : enabling to send auht tokens in req body instead of headers * [FLPATH-2143] : enabling to send auht tokens in req body instead of headers * [FLPATH-2143] : enabling to send auht tokens in req body instead of headers * [FLPATH-2143] : enabling to send auht tokens in req body instead of headers * [FLPATH-2143] : enabling to send auht tokens in req body instead of headers * [FLPATH-2143] : enabling to send auht tokens in req body instead of headers --------- Co-authored-by: Marek Libra <marek.libra@gmail.com>
1 parent 952290d commit d63524c

4 files changed

Lines changed: 44 additions & 1 deletion

File tree

workspaces/orchestrator/plugins/orchestrator-backend/src/service/OrchestratorService.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
WorkflowExecutionResponse,
2323
WorkflowInfo,
2424
WorkflowOverview,
25+
AuthToken,
2526
} from '@red-hat-developer-hub/backstage-plugin-orchestrator-common';
2627

2728
import { Pagination } from '../types/pagination';
@@ -185,6 +186,7 @@ export class OrchestratorService {
185186
definitionId: string;
186187
serviceUrl: string;
187188
inputData?: ProcessInstanceVariables;
189+
authTokens?: Array<AuthToken>;
188190
businessKey?: string;
189191
cacheHandler?: CacheHandler;
190192
}): Promise<WorkflowExecutionResponse | undefined> {

workspaces/orchestrator/plugins/orchestrator-backend/src/service/SonataFlowService.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
WorkflowExecutionResponse,
2828
WorkflowInfo,
2929
WorkflowOverview,
30+
AuthToken,
3031
} from '@red-hat-developer-hub/backstage-plugin-orchestrator-common';
3132

3233
import { Pagination } from '../types/pagination';
@@ -100,16 +101,34 @@ export class SonataFlowService {
100101
definitionId: string;
101102
serviceUrl: string;
102103
inputData?: ProcessInstanceVariables;
104+
authTokens?: Array<AuthToken>;
103105
businessKey?: string;
104106
}): Promise<WorkflowExecutionResponse | undefined> {
105107
const urlToFetch = args.businessKey
106108
? `${args.serviceUrl}/${args.definitionId}?businessKey=${args.businessKey}`
107109
: `${args.serviceUrl}/${args.definitionId}`;
110+
const headers: Record<string, string> = {
111+
'Content-Type': 'application/json',
112+
};
113+
114+
// Add X-Authentication headers from authTokens
115+
if (args.authTokens && Array.isArray(args.authTokens)) {
116+
args.authTokens.forEach((tokenObj) => {
117+
if (tokenObj.provider && tokenObj.token) {
118+
const headerKey = `X-Authentication-${tokenObj.provider}`;
119+
headers[headerKey] = String(tokenObj.token); // Ensure token is a string
120+
}
121+
});
122+
}
123+
124+
else {
125+
this.logger.debug('No authTokens provided or authTokens is not an array.');
126+
}
108127

109128
const response = await fetch(urlToFetch, {
110129
method: 'POST',
111130
body: JSON.stringify(args.inputData || {}),
112-
headers: { 'content-type': 'application/json' },
131+
headers,
113132
});
114133

115134
const json = await response.json();

workspaces/orchestrator/plugins/orchestrator-backend/src/service/api/v2.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { ParsedRequest } from 'openapi-backend';
1818

1919
import {
2020
AssessedProcessInstanceDTO,
21+
AuthToken,
2122
ExecuteWorkflowRequestDTO,
2223
ExecuteWorkflowResponseDTO,
2324
Filter,
@@ -176,6 +177,8 @@ export class V2 {
176177
definitionId: workflowId,
177178
inputData:
178179
executeWorkflowRequestDTO.inputData as ProcessInstanceVariables,
180+
authTokens:
181+
executeWorkflowRequestDTO.authTokens as Array<AuthToken>,
179182
serviceUrl: definition.serviceUrl,
180183
businessKey,
181184
cacheHandler: 'throw',

workspaces/orchestrator/plugins/orchestrator-common/src/openapi/openapi.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,25 @@ components:
575575
inputData:
576576
type: object
577577
additionalProperties: true
578+
authTokens:
579+
type: array
580+
items:
581+
$ref: '#/components/schemas/AuthToken'
582+
minItems: 1
583+
additionalProperties: true
584+
AuthToken:
585+
type: object
586+
properties:
587+
provider:
588+
description: The auth token provider name
589+
type: string
590+
token:
591+
description: The auth token itself retrieved from the above specified provider name
592+
type: string
593+
required:
594+
- provider
595+
- token
596+
additionalProperties: false
578597
ExecuteWorkflowResponseDTO:
579598
type: object
580599
properties:

0 commit comments

Comments
 (0)