diff --git a/src/main/java/com/laserfiche/api/client/apiserver/TokenClientImpl.java b/src/main/java/com/laserfiche/api/client/apiserver/TokenClientImpl.java index 2d27474..0d21f43 100644 --- a/src/main/java/com/laserfiche/api/client/apiserver/TokenClientImpl.java +++ b/src/main/java/com/laserfiche/api/client/apiserver/TokenClientImpl.java @@ -9,6 +9,7 @@ import com.laserfiche.api.client.model.SessionKeyInfo; import com.laserfiche.api.client.tokenclients.BaseTokenClient; import kong.unirest.HttpResponse; +import kong.unirest.MultipartBody; import kong.unirest.json.JSONObject; import java.util.HashMap; @@ -36,17 +37,26 @@ public SessionKeyInfo createAccessToken(String repositoryId, CreateConnectionReq Map pathParameters = getNonNullParameters(new String[]{"repoId"}, new Object[]{repositoryId}); - HttpResponse httpResponse = httpClient + MultipartBody request = httpClient .post(baseUrl + "/v1/Repositories/{repoId}/Token") .routeParam(pathParameters) .header("Accept", "application/json") .header("Content-Type", "application/x-www-form-urlencoded") - .field("grant_type", "password") - .field("username", body - .getUsername()) - .field("password", body - .getPassword()) - .asObject(Object.class); + .field("grant_type", "password"); + if (body != null) { + if (body.getUsername() != null) { + request = request.field("username", body + .getUsername()); + } + if (body.getPassword() != null) { + request = request.field("password", body + .getPassword()); + } + } + + HttpResponse httpResponse = request.asObject(Object.class); + + Map headersMap = getHeadersMap(httpResponse); if (httpResponse.getStatus() == 200) { try { diff --git a/src/main/java/com/laserfiche/api/client/tokenclients/TokenClientUtils.java b/src/main/java/com/laserfiche/api/client/tokenclients/TokenClientUtils.java index 9970293..15e79a4 100644 --- a/src/main/java/com/laserfiche/api/client/tokenclients/TokenClientUtils.java +++ b/src/main/java/com/laserfiche/api/client/tokenclients/TokenClientUtils.java @@ -44,6 +44,10 @@ public static String getOAuthApiBaseUri(String domain) { * @return Bearer header. */ public static String createBearer(String servicePrincipalKey, AccessKey accessKey) { + if (accessKey.getJwk() == null) { + return null; + } + // Prepare JWK ECKey jwk = accessKey.getJwk().toECKey();