Description
Expected behavior
Perform request graphClient.applications().byApplicationId("") .patch(app) if try to add a new certificate and there are old configured certificates.
If there are not old configured certificates the call is successful!
Actual behavior
java.time.format.DateTimeParseException: Text '2024-02-14T07:37:32' could not be parsed at index 19
at java.base/java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:2052)
at java.base/java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1954)
at java.base/java.time.OffsetDateTime.parse(OffsetDateTime.java:404)
at java.base/java.time.OffsetDateTime.parse(OffsetDateTime.java:389)
at com.microsoft.kiota.serialization.JsonParseNode.getOffsetDateTimeValue(JsonParseNode.java:98)
at com.microsoft.graph.models.odataerrors.InnerError.lambda$getFieldDeserializers$1(InnerError.java:83)
at com.microsoft.kiota.serialization.JsonParseNode.assignFieldValues(JsonParseNode.java:247)
at com.microsoft.kiota.serialization.JsonParseNode.getObjectValue(JsonParseNode.java:198)
at com.microsoft.graph.models.odataerrors.MainError.lambda$getFieldDeserializers$2(MainError.java:83)
at com.microsoft.kiota.serialization.JsonParseNode.assignFieldValues(JsonParseNode.java:247)
at com.microsoft.kiota.serialization.JsonParseNode.getObjectValue(JsonParseNode.java:198)
at com.microsoft.graph.models.odataerrors.ODataError.lambda$getFieldDeserializers$0(ODataError.java:74)
at com.microsoft.kiota.serialization.JsonParseNode.assignFieldValues(JsonParseNode.java:247)
at com.microsoft.kiota.serialization.JsonParseNode.getObjectValue(JsonParseNode.java:198)
at com.microsoft.kiota.http.OkHttpRequestAdapter.lambda$throwIfFailedResponse$0(OkHttpRequestAdapter.java:672)
at com.microsoft.kiota.ApiExceptionBuilder.(ApiExceptionBuilder.java:26)
at com.microsoft.kiota.http.OkHttpRequestAdapter.throwIfFailedResponse(OkHttpRequestAdapter.java:671)
at com.microsoft.kiota.http.OkHttpRequestAdapter.send(OkHttpRequestAdapter.java:279)
at com.microsoft.graph.applications.item.ApplicationItemRequestBuilder.patch(ApplicationItemRequestBuilder.java:273)
at com.microsoft.graph.applications.item.ApplicationItemRequestBuilder.patch(ApplicationItemRequestBuilder.java:257)
Steps to reproduce the behavior
TokenCredential tokenCredential = new ClientCertificateCredentialBuilder().tenantId(tenantId)
.clientId(clientId).pfxCertificate(pfxCertificatePath).clientCertificatePassword(pfxPassword)
.build();
String[] scopes = new String[] { "https://graph.microsoft.com/.default" };
GraphServiceClient graphClient = new GraphServiceClient(tokenCredential, scopes);
Application app = graphClient.applications().byApplicationId("<my app id>").get();
List<KeyCredential> keyCredentialList = app.getKeyCredentials(); // There are old KeyCredentials
X509Certificate certificate = ... //new certificate
KeyCredential newKey = new KeyCredential();
newKey.setType("AsymmetricX509Cert");
newKey.setUsage("Verify");
newKey.setKey(certificate.getEncoded());
keyCredentialList.add(newKey);
app.setKeyCredentials(keyCredentialList);
Application updatedApp = graphClient.applications().byApplicationId("<my app id>")
.patch(app);
Workaround
TokenCredential tokenCredential = new ClientCertificateCredentialBuilder().tenantId(tenantId)
.clientId(clientId).pfxCertificate(pfxCertificatePath).clientCertificatePassword(pfxPassword)
.build();
String[] scopes = new String[] { "https://graph.microsoft.com/.default" };
GraphServiceClient graphClient = new GraphServiceClient(tokenCredential, scopes);
Application app = graphClient.applications().byApplicationId("<my app id>").get();
List<KeyCredential> keyCredentialListOld = app.getKeyCredentials(); // There are old KeyCredentials
// create a new Key Credential List and add old Key Credentials as using getters and setters
List<KeyCredential> keyCredentialList = new ArrayList<>();
for (KeyCredential key : keyCredentialListOld) {
KeyCredential oldKey = new KeyCredential();
oldKey.setDisplayName(key.getDisplayName());
oldKey.setCustomKeyIdentifier(key.getCustomKeyIdentifier());
oldKey.setKeyId(key.getKeyId());
oldKey.setKey(key.getKey());
oldKey.setStartDateTime(key.getStartDateTime());
oldKey.setEndDateTime(key.getEndDateTime());
oldKey.setUsage(key.getUsage());
oldKey.setType(key.getType());
keyCredentialList.add(oldKey);
}
X509Certificate certificate = ... //new certificate
KeyCredential newKey = new KeyCredential();
newKey.setType("AsymmetricX509Cert");
newKey.setUsage("Verify");
newKey.setKey(certificate.getEncoded());
keyCredentialList.add(newKey);
app.setKeyCredentials(keyCredentialList);
Application updatedApp = graphClient.applications().byApplicationId("<my app id>")
.patch(app);