]> git.basschouten.com Git - openhab-addons.git/commitdiff
[iCloud] Ignore HTTP errors != 400 & >= 500 for 2-FA authentication (#14563)
authorSimon Spielmann <simon.spielmann@gmx.de>
Fri, 10 Mar 2023 20:53:35 +0000 (21:53 +0100)
committerGitHub <noreply@github.com>
Fri, 10 Mar 2023 20:53:35 +0000 (21:53 +0100)
* Ignore HTTP errors != 400 for 2-FA authentication

---------

Signed-off-by: Simon Spielmann <simon.spielmann@gmx.de>
bundles/org.openhab.binding.icloud/src/main/java/org/openhab/binding/icloud/internal/ICloudService.java

index e67cdabd0f6f5aac2929a818b9ddca834efa89f8..511620192942c5d9e24da28273ec000136d8eed5 100644 (file)
@@ -246,8 +246,14 @@ public class ICloudService {
             this.session.post(AUTH_ENDPOINT + "/verify/trusteddevice/securitycode", JsonUtils.toJson(requestBody),
                     headers);
         } catch (ICloudApiResponseException ex) {
-            logger.debug("Code verification failed.", ex);
-            return false;
+            logger.trace("Exception on code verification with HTTP status {}. Verification might still be successful.",
+                    ex.getStatusCode(), ex);
+            // iCloud API returns different 4xx error codes even if validation is successful
+            // currently 400 seems to show that verification "really" failed.
+            if (ex.getStatusCode() == 400 || ex.getStatusCode() >= 500) {
+                this.logger.debug("Verification failed with HTTP status {}.", ex.getStatusCode());
+                return false;
+            }
         }
 
         logger.debug("Code verification successful.");