Skip to content

Commit

Permalink
fix: update request content
Browse files Browse the repository at this point in the history
  • Loading branch information
mbiciin authored and chillleader committed Dec 8, 2022
1 parent 6f41976 commit 294f1eb
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 11 deletions.
28 changes: 28 additions & 0 deletions connectors/http-json/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,34 @@ The response will contain the status code, the headers and the body of the respo
}
```

### Input (OAuth)

```json
{
"method": "post",
"url": "https://youroauthclientdomainname.eu.auth0.com/oauth/token",
"authentication": {
"oauthTokenEndpoint":"secrets.OAUTH_TOKEN_ENDPOINT_KEY",
"scopes": "read:clients read:users",
"audience":"secrets.AUDIENCE_KEY",
"clientId":"secrets.CLIENT_ID_KEY",
"clientSecret":"secrets.CLIENT_SECRET_KEY",
"type": "oauth-client-credentials-flow",
"clientAuthentication":"secrets.CLIENT_AUTHENTICATION_KEY"
}
}
```

### Output (Access Token)

```json
{
"access_token":"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IlUtN2N6WG1sMzljUFNfUnlQQkNMWCJ9.kjhwfjkhfejkrhfbwjkfbhetcetc",
"scope":"read:clients create:users",
"expires_in":86400,
"token_type":"Bearer"
}
```
### Error codes

The Connector will fail on any non-2XX HTTP status code in the response. This error status code will be passed on as error code, e.g. "404".
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,6 @@
"type": "zeebe:input",
"name": "authentication.audience"
},
"constraints": {
"notEmpty": true
},
"condition": {
"property": "authenticationType",
"equals": "oauth-client-credentials-flow"
Expand Down
2 changes: 1 addition & 1 deletion connectors/http-json/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
<dependency>
<groupId>io.camunda.connector</groupId>
<artifactId>connector-runtime-cloud</artifactId>
<version>0.4.0-SNAPSHOT</version>
<version>0.3.0</version>
</dependency>
<dependency>
<groupId>io.camunda.connector</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import com.google.api.client.http.HttpRequestFactory;
import com.google.api.client.http.HttpResponse;
import com.google.api.client.http.HttpResponseException;
import com.google.api.client.http.json.JsonHttpContent;
import com.google.api.client.http.UrlEncodedContent;
import com.google.api.client.json.gson.GsonFactory;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
Expand Down Expand Up @@ -147,19 +147,19 @@ protected HttpRequest createOAuthRequest(HttpJsonRequest request) throws IOExcep

final GenericUrl genericUrl = new GenericUrl(authentication.getOauthTokenEndpoint());
Map<String, String> data = getDataForAuthRequestBody(authentication);
HttpContent content = new JsonHttpContent(gsonFactory, data);
HttpContent content = new UrlEncodedContent(data);
final String method = Constants.POST;

final var httpRequest = requestFactory.buildRequest(method, genericUrl, content);
httpRequest.setFollowRedirects(false);
setTimeout(request, httpRequest);
HttpHeaders headers = new HttpHeaders();

if (authentication.getClientAuthentication().equals(Constants.BASIC_AUTH_HEADER)) {
HttpHeaders headers = new HttpHeaders();
headers.setBasicAuthentication(
authentication.getClientId(), authentication.getClientSecret());
httpRequest.setHeaders(headers);
}
headers.setContentType(Constants.APPLICATION_X_WWW_FORM_URLENCODED);
httpRequest.setHeaders(headers);
return httpRequest;
}

Expand Down Expand Up @@ -202,7 +202,7 @@ protected HttpJsonResult executeRequestViaProxy(String proxyUrl, HttpJsonRequest
// hence write it ourselves:
String contentAsJson = gson.toJson(request);
HttpContent content =
new AbstractHttpContent("application/json; charset=UTF-8") {
new AbstractHttpContent(Constants.APPLICATION_JSON_CHARSET_UTF_8) {
public void writeTo(OutputStream outputStream) throws IOException {
outputStream.write(contentAsJson.getBytes(StandardCharsets.UTF_8));
}
Expand Down Expand Up @@ -258,7 +258,7 @@ protected void setTimeout(HttpJsonRequest request, HttpRequest httpRequest) {

protected HttpContent createContent(final HttpJsonRequest request) {
if (request.hasBody()) {
return new JsonHttpContent(gsonFactory, request.getBody());
return new UrlEncodedContent(request.hasBody());
} else {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@ public class Constants {
public static final String CREDENTIALS_BODY = "credentialsBody";
public static final String PROXY_FUNCTION_URL_ENV_NAME = "CAMUNDA_CONNECTOR_HTTP_PROXY_URL";
public static final String POST = "POST";
public static final String APPLICATION_JSON_CHARSET_UTF_8 = "application/json; charset=UTF-8";
public static final String APPLICATION_X_WWW_FORM_URLENCODED =
"application/x-www-form-urlencoded";
}

0 comments on commit 294f1eb

Please sign in to comment.