Skip to content

Commit cdce90e

Browse files
Merge pull request #139 from camunda-community-hub/fix/respect-scope
respect scope for token request
2 parents 6e701cf + 8a98b1c commit cdce90e

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

extension/client-java/src/main/java/io/camunda/tasklist/CamundaTaskListClientBuilder.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,16 @@ public CamundaTaskListClientBuilder selfManagedAuthentication(
7979

8080
public CamundaTaskListClientBuilder selfManagedAuthentication(
8181
String clientId, String clientSecret, String audience, String keycloakUrl) {
82+
return selfManagedAuthentication(clientId, clientSecret, "tasklist-api", null, keycloakUrl);
83+
}
84+
85+
public CamundaTaskListClientBuilder selfManagedAuthentication(
86+
String clientId, String clientSecret, String audience, String scope, String authUrl) {
8287
try {
8388
properties.setAuthentication(
8489
new JwtAuthentication(
85-
new JwtCredential(clientId, clientSecret, audience, URI.create(keycloakUrl).toURL()),
90+
new JwtCredential(
91+
clientId, clientSecret, audience, URI.create(authUrl).toURL(), scope),
8692
new JacksonTokenResponseMapper(new ObjectMapper())));
8793
} catch (MalformedURLException e) {
8894
throw new RuntimeException("Error while parsing keycloak url", e);
@@ -98,7 +104,8 @@ public CamundaTaskListClientBuilder saaSAuthentication(String clientId, String c
98104
clientId,
99105
clientSecret,
100106
"tasklist.camunda.io",
101-
URI.create("https://login.cloud.camunda.io/oauth/token").toURL()),
107+
URI.create("https://login.cloud.camunda.io/oauth/token").toURL(),
108+
null),
102109
new JacksonTokenResponseMapper(new ObjectMapper())));
103110
} catch (MalformedURLException e) {
104111
throw new RuntimeException("Error while parsing token url", e);

extension/client-java/src/main/java/io/camunda/tasklist/auth/JwtAuthentication.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ private HttpPost buildRequest() throws URISyntaxException {
7373
formParams.add(new BasicNameValuePair("client_id", jwtCredential.clientId()));
7474
formParams.add(new BasicNameValuePair("client_secret", jwtCredential.clientSecret()));
7575
formParams.add(new BasicNameValuePair("audience", jwtCredential.audience()));
76+
if (jwtCredential.scope() != null) {
77+
formParams.add(new BasicNameValuePair("scope", jwtCredential.scope()));
78+
}
7679
httpPost.setEntity(new UrlEncodedFormEntity(formParams));
7780
return httpPost;
7881
}

extension/client-java/src/main/java/io/camunda/tasklist/auth/JwtCredential.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
import java.net.URL;
44

5-
public record JwtCredential(String clientId, String clientSecret, String audience, URL authUrl) {}
5+
public record JwtCredential(
6+
String clientId, String clientSecret, String audience, URL authUrl, String scope) {}

extension/client-java/src/test/java/io/camunda/tasklist/CamundaTasklistClientTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ void shouldAuthenticateUsingJwt() throws MalformedURLException, TaskListExceptio
100100
properties.setAuthentication(
101101
new JwtAuthentication(
102102
new JwtCredential(
103-
"abc", "abc", "tasklist-api", URI.create(BASE_URL + "/token").toURL()),
103+
"abc", "abc", "tasklist-api", URI.create(BASE_URL + "/token").toURL(), null),
104104
new JacksonTokenResponseMapper(new ObjectMapper())));
105105
CamundaTaskListClient client = new CamundaTaskListClient(properties, null);
106106
assertNotNull(client);

0 commit comments

Comments
 (0)