Skip to content

Commit 414b5b2

Browse files
committed
tests and fixies
Signed-off-by: Dmitrii Tikhomirov <[email protected]>
1 parent 6f56995 commit 414b5b2

17 files changed

+1038
-52
lines changed

impl/http/src/main/java/io/serverlessworkflow/impl/executors/http/oauth/HttpRequestBuilder.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@
3535
import jakarta.ws.rs.core.Form;
3636
import jakarta.ws.rs.core.MediaType;
3737
import java.net.URI;
38-
import java.net.URLEncoder;
39-
import java.nio.charset.StandardCharsets;
4038
import java.util.HashMap;
4139
import java.util.Map;
4240
import java.util.Objects;
@@ -115,21 +113,17 @@ InvocationHolder build(WorkflowContext workflow, TaskContext task, WorkflowModel
115113
form.param("grant_type", grantType.value());
116114
queryParams.forEach(
117115
(key, value) -> {
118-
String v = value.apply(workflow, task, model);
119-
String encodedKey = URLEncoder.encode(key, StandardCharsets.UTF_8);
120-
String encodedValue = URLEncoder.encode(v, StandardCharsets.UTF_8);
121-
form.param(encodedKey, encodedValue);
116+
String resolved = value.apply(workflow, task, model);
117+
form.param(key, resolved);
122118
});
123119
entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED);
124120
} else {
125121
Map<String, Object> jsonData = new HashMap<>();
126122
jsonData.put("grant_type", grantType.value());
127123
queryParams.forEach(
128124
(key, value) -> {
129-
String v = value.apply(workflow, task, model);
130-
String encodedKey = URLEncoder.encode(key, StandardCharsets.UTF_8);
131-
String encodedValue = URLEncoder.encode(v, StandardCharsets.UTF_8);
132-
jsonData.put(encodedKey, encodedValue);
125+
String resolved = value.apply(workflow, task, model);
126+
jsonData.put(key, resolved);
133127
});
134128
entity = Entity.entity(jsonData, MediaType.APPLICATION_JSON);
135129
}

impl/http/src/main/java/io/serverlessworkflow/impl/executors/http/oauth/OAuthRequestBuilder.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@
2727
import io.serverlessworkflow.impl.WorkflowContext;
2828
import io.serverlessworkflow.impl.WorkflowModel;
2929
import java.net.URI;
30+
import java.util.Arrays;
3031
import java.util.List;
3132
import java.util.Map;
33+
import java.util.Objects;
34+
import java.util.stream.Collectors;
3235

3336
public class OAuthRequestBuilder {
3437

@@ -112,9 +115,21 @@ public void audience(HttpRequestBuilder requestBuilder) {
112115
}
113116

114117
private void scope(HttpRequestBuilder requestBuilder) {
115-
if (authenticationData.getScopes() != null && !authenticationData.getScopes().isEmpty()) {
116-
String scopes = String.join(" ", authenticationData.getScopes());
117-
requestBuilder.addQueryParam("scope", scopes);
118+
List<String> scopesList = authenticationData.getScopes();
119+
if (scopesList == null || scopesList.isEmpty()) {
120+
return;
121+
}
122+
String scope =
123+
scopesList.stream()
124+
.filter(Objects::nonNull)
125+
.map(String::trim)
126+
.filter(s -> !s.isEmpty())
127+
.flatMap(s -> Arrays.stream(s.split("\\s+")))
128+
.distinct()
129+
.collect(Collectors.joining(" "));
130+
131+
if (!scope.isEmpty()) {
132+
requestBuilder.addQueryParam("scope", scope);
118133
}
119134
}
120135

0 commit comments

Comments
 (0)