Skip to content

Commit 1d71c48

Browse files
committed
Finalize handling for open api oauth inherit from login workflow
1 parent 085a9d0 commit 1d71c48

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

server/api-service/lowcoder-domain/src/main/java/org/lowcoder/domain/query/service/QueryExecutionService.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,9 @@ private Mono<QueryExecutionResult> executeByNodeJs(Datasource datasource, Map<St
113113
private Mono<Void> injectOauth2Token(QueryVisitorContext queryVisitorContext, List<Map<String, Object>> context) {
114114
return queryVisitorContext.getAuthTokenMono()
115115
.doOnNext(properties -> {
116-
HashMap<String, Object> hashMap = new HashMap<>();
117116
for (Property property : properties) {
118-
hashMap.put(property.getKey(), property.getValue());
117+
context.add(Map.of("key" , property.getKey(), "value", property.getValue()));
119118
}
120-
context.add(hashMap);
121119
})
122120
.then();
123121
}

server/node-service/src/plugins/openApi/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export async function runOpenApi(
102102

103103
try {
104104
const { parameters, requestBody } = normalizeParams(otherActionData, operation, isOas3Spec);
105-
const securities = extractSecurityParams(dataSourceConfig.dynamicParamsConfig, definition);
105+
let securities = extractSecurityParams(dataSourceConfig, definition);
106106
const response = await SwaggerClient.execute({
107107
spec: definition,
108108
operationId: realOperationId,

server/node-service/src/plugins/openApi/util.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ interface NormalizedParams {
8181
requestBody?: any;
8282
}
8383

84-
export function extractSecurityParams(config: any, spec: OpenAPI.Document) {
84+
export function extractSecurityParams(datasourceConfig: any, spec: OpenAPI.Document) {
85+
const config = datasourceConfig.dynamicParamsConfig;
8586
if (!config) {
8687
return {};
8788
}
@@ -96,6 +97,18 @@ export function extractSecurityParams(config: any, spec: OpenAPI.Document) {
9697
names = Object.keys(swagger2Spec.securityDefinitions || {});
9798
}
9899
const authorized = _.pick(authData, names);
100+
101+
let oauthAccessToken = datasourceConfig["OAUTH_ACCESS_TOKEN"];
102+
103+
if(oauthAccessToken) {
104+
return {
105+
authorized: {
106+
OAUTH_ACCESS_TOKEN: { value: oauthAccessToken }
107+
},
108+
specSecurity: []
109+
};
110+
}
111+
99112
return { authorized, specSecurity: spec.security };
100113
}
101114

server/node-service/src/services/plugin.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,12 @@ export async function runPluginQuery(
212212
const queryConfig = await getQueryConfig(plugin, dataSourceConfig);
213213
const action = await evalToValue(queryConfig, dsl, context, dataSourceConfig);
214214

215-
//forward cookies
215+
// forward cookies
216216
context.forEach(({ key, value }) => {
217-
if (dataSourceConfig.dynamicParamsConfig && key in dataSourceConfig.dynamicParamsConfig) {
217+
// for oauth(inherit from login) support
218+
if(key == "OAUTH_ACCESS_TOKEN") {
219+
dataSourceConfig["OAUTH_ACCESS_TOKEN"] = value
220+
} else if (dataSourceConfig.dynamicParamsConfig && key in dataSourceConfig.dynamicParamsConfig) {
218221
const valueKey = `${key}.value`;
219222
dataSourceConfig.dynamicParamsConfig[valueKey] = value[0].value
220223
}

0 commit comments

Comments
 (0)