|
12 | 12 | import com.auth0.client.mgmt.core.OptionalNullable; |
13 | 13 | import com.auth0.client.mgmt.core.RequestOptions; |
14 | 14 | import com.auth0.client.mgmt.errors.BadRequestError; |
| 15 | +import com.auth0.client.mgmt.errors.ConflictError; |
15 | 16 | import com.auth0.client.mgmt.errors.ForbiddenError; |
16 | 17 | import com.auth0.client.mgmt.errors.NotFoundError; |
17 | 18 | import com.auth0.client.mgmt.errors.TooManyRequestsError; |
18 | 19 | import com.auth0.client.mgmt.errors.UnauthorizedError; |
19 | 20 | import com.auth0.client.mgmt.types.ConnectionKey; |
| 21 | +import com.auth0.client.mgmt.types.PostConnectionKeysRequestContent; |
| 22 | +import com.auth0.client.mgmt.types.PostConnectionsKeysResponseContentItem; |
20 | 23 | import com.auth0.client.mgmt.types.RotateConnectionKeysRequestContent; |
21 | 24 | import com.auth0.client.mgmt.types.RotateConnectionsKeysResponseContent; |
22 | 25 | import com.fasterxml.jackson.core.JsonProcessingException; |
@@ -135,6 +138,134 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) { |
135 | 138 | return future; |
136 | 139 | } |
137 | 140 |
|
| 141 | + /** |
| 142 | + * Provision initial connection keys for Okta or OIDC connection strategies. This endpoint allows you to create keys before configuring the connection to use Private Key JWT authentication, enabling zero-downtime transitions. |
| 143 | + */ |
| 144 | + public CompletableFuture<ManagementApiHttpResponse<List<PostConnectionsKeysResponseContentItem>>> create( |
| 145 | + String id) { |
| 146 | + return create(id, OptionalNullable.<PostConnectionKeysRequestContent>absent()); |
| 147 | + } |
| 148 | + |
| 149 | + /** |
| 150 | + * Provision initial connection keys for Okta or OIDC connection strategies. This endpoint allows you to create keys before configuring the connection to use Private Key JWT authentication, enabling zero-downtime transitions. |
| 151 | + */ |
| 152 | + public CompletableFuture<ManagementApiHttpResponse<List<PostConnectionsKeysResponseContentItem>>> create( |
| 153 | + String id, RequestOptions requestOptions) { |
| 154 | + return create(id, OptionalNullable.<PostConnectionKeysRequestContent>absent(), requestOptions); |
| 155 | + } |
| 156 | + |
| 157 | + /** |
| 158 | + * Provision initial connection keys for Okta or OIDC connection strategies. This endpoint allows you to create keys before configuring the connection to use Private Key JWT authentication, enabling zero-downtime transitions. |
| 159 | + */ |
| 160 | + public CompletableFuture<ManagementApiHttpResponse<List<PostConnectionsKeysResponseContentItem>>> create( |
| 161 | + String id, OptionalNullable<PostConnectionKeysRequestContent> request) { |
| 162 | + return create(id, request, null); |
| 163 | + } |
| 164 | + |
| 165 | + /** |
| 166 | + * Provision initial connection keys for Okta or OIDC connection strategies. This endpoint allows you to create keys before configuring the connection to use Private Key JWT authentication, enabling zero-downtime transitions. |
| 167 | + */ |
| 168 | + public CompletableFuture<ManagementApiHttpResponse<List<PostConnectionsKeysResponseContentItem>>> create( |
| 169 | + String id, OptionalNullable<PostConnectionKeysRequestContent> request, RequestOptions requestOptions) { |
| 170 | + HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) |
| 171 | + .newBuilder() |
| 172 | + .addPathSegments("connections") |
| 173 | + .addPathSegment(id) |
| 174 | + .addPathSegments("keys"); |
| 175 | + if (requestOptions != null) { |
| 176 | + requestOptions.getQueryParameters().forEach((_key, _value) -> { |
| 177 | + httpUrl.addQueryParameter(_key, _value); |
| 178 | + }); |
| 179 | + } |
| 180 | + RequestBody body; |
| 181 | + try { |
| 182 | + body = RequestBody.create("", null); |
| 183 | + if (request.isPresent()) { |
| 184 | + body = RequestBody.create( |
| 185 | + ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); |
| 186 | + } |
| 187 | + } catch (JsonProcessingException e) { |
| 188 | + throw new ManagementException("Failed to serialize request", e); |
| 189 | + } |
| 190 | + Request okhttpRequest = new Request.Builder() |
| 191 | + .url(httpUrl.build()) |
| 192 | + .method("POST", body) |
| 193 | + .headers(Headers.of(clientOptions.headers(requestOptions))) |
| 194 | + .addHeader("Content-Type", "application/json") |
| 195 | + .addHeader("Accept", "application/json") |
| 196 | + .build(); |
| 197 | + OkHttpClient client = clientOptions.httpClient(); |
| 198 | + if (requestOptions != null && requestOptions.getTimeout().isPresent()) { |
| 199 | + client = clientOptions.httpClientWithTimeout(requestOptions); |
| 200 | + } |
| 201 | + CompletableFuture<ManagementApiHttpResponse<List<PostConnectionsKeysResponseContentItem>>> future = |
| 202 | + new CompletableFuture<>(); |
| 203 | + client.newCall(okhttpRequest).enqueue(new Callback() { |
| 204 | + @Override |
| 205 | + public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { |
| 206 | + try (ResponseBody responseBody = response.body()) { |
| 207 | + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; |
| 208 | + if (response.isSuccessful()) { |
| 209 | + future.complete(new ManagementApiHttpResponse<>( |
| 210 | + ObjectMappers.JSON_MAPPER.readValue( |
| 211 | + responseBodyString, |
| 212 | + new TypeReference<List<PostConnectionsKeysResponseContentItem>>() {}), |
| 213 | + response)); |
| 214 | + return; |
| 215 | + } |
| 216 | + try { |
| 217 | + switch (response.code()) { |
| 218 | + case 400: |
| 219 | + future.completeExceptionally(new BadRequestError( |
| 220 | + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), |
| 221 | + response)); |
| 222 | + return; |
| 223 | + case 401: |
| 224 | + future.completeExceptionally(new UnauthorizedError( |
| 225 | + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), |
| 226 | + response)); |
| 227 | + return; |
| 228 | + case 403: |
| 229 | + future.completeExceptionally(new ForbiddenError( |
| 230 | + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), |
| 231 | + response)); |
| 232 | + return; |
| 233 | + case 404: |
| 234 | + future.completeExceptionally(new NotFoundError( |
| 235 | + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), |
| 236 | + response)); |
| 237 | + return; |
| 238 | + case 409: |
| 239 | + future.completeExceptionally(new ConflictError( |
| 240 | + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), |
| 241 | + response)); |
| 242 | + return; |
| 243 | + case 429: |
| 244 | + future.completeExceptionally(new TooManyRequestsError( |
| 245 | + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), |
| 246 | + response)); |
| 247 | + return; |
| 248 | + } |
| 249 | + } catch (JsonProcessingException ignored) { |
| 250 | + // unable to map error response, throwing generic error |
| 251 | + } |
| 252 | + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); |
| 253 | + future.completeExceptionally(new ManagementApiException( |
| 254 | + "Error with status code " + response.code(), response.code(), errorBody, response)); |
| 255 | + return; |
| 256 | + } catch (IOException e) { |
| 257 | + future.completeExceptionally(new ManagementException("Network error executing HTTP request", e)); |
| 258 | + } |
| 259 | + } |
| 260 | + |
| 261 | + @Override |
| 262 | + public void onFailure(@NotNull Call call, @NotNull IOException e) { |
| 263 | + future.completeExceptionally(new ManagementException("Network error executing HTTP request", e)); |
| 264 | + } |
| 265 | + }); |
| 266 | + return future; |
| 267 | + } |
| 268 | + |
138 | 269 | /** |
139 | 270 | * Rotates the connection keys for the Okta or OIDC connection strategies. |
140 | 271 | */ |
|
0 commit comments