From 230392dc1e6b0b44114a3816cf8b22e03068697b Mon Sep 17 00:00:00 2001 From: andan67 Date: Sun, 12 Sep 2021 13:15:56 +0200 Subject: [PATCH] Fix of Forbidden error when auth cookie gets expired --- .../binding/sony/internal/transports/SonyAuthFilter.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bundles/org.openhab.binding.sony/src/main/java/org/openhab/binding/sony/internal/transports/SonyAuthFilter.java b/bundles/org.openhab.binding.sony/src/main/java/org/openhab/binding/sony/internal/transports/SonyAuthFilter.java index f60d450f95f1a..284b1ec1438d1 100644 --- a/bundles/org.openhab.binding.sony/src/main/java/org/openhab/binding/sony/internal/transports/SonyAuthFilter.java +++ b/bundles/org.openhab.binding.sony/src/main/java/org/openhab/binding/sony/internal/transports/SonyAuthFilter.java @@ -143,9 +143,14 @@ public void filter(final @Nullable ClientRequestContext requestCtx) throws IOExc if (newCookies != null) { final NewCookie authCookie = newCookies.get(AUTHCOOKIENAME); if (authCookie != null) { + // create cookie with expiry date using 80% of maxAge given in seconds + final Date expiryDate = new Date(new Date().getTime() + 800L *authCookie.getMaxAge()); + final NewCookie newAuthCookieToStore = new NewCookie( + authCookie.toCookie(), authCookie.getComment(), authCookie.getMaxAge(), + expiryDate, authCookie.isSecure(), authCookie.isHttpOnly()); logger.debug("Authorization cookie was renewed"); - logger.debug("New auth cookie: {} for host: {}", authCookie.getValue(), host); - authCookieStore.setAuthCookieForHost(host, authCookie); + logger.debug("New auth cookie: {} for host: {}", newAuthCookieToStore.getValue(), host); + authCookieStore.setAuthCookieForHost(host, newAuthCookieToStore); } else { logger.debug("No authorization cookie was returned"); }