From 7d64617897c7932764660375a4fca5d0d765d691 Mon Sep 17 00:00:00 2001 From: mathijs-bb Date: Thu, 12 Feb 2026 15:22:48 +0100 Subject: [PATCH] Added proactive token expiry validation --- Apps.Crowdin/Apps.Crowdin.csproj | 2 +- .../Connections/OAuth/OAuth2TokenService.cs | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Apps.Crowdin/Apps.Crowdin.csproj b/Apps.Crowdin/Apps.Crowdin.csproj index ef36f85..d96c9d4 100644 --- a/Apps.Crowdin/Apps.Crowdin.csproj +++ b/Apps.Crowdin/Apps.Crowdin.csproj @@ -5,7 +5,7 @@ enable Crowdin Cloud-based solution that streamlines localization management - 1.2.36 + 1.2.37 Apps.Crowdin diff --git a/Apps.Crowdin/Connections/OAuth/OAuth2TokenService.cs b/Apps.Crowdin/Connections/OAuth/OAuth2TokenService.cs index db8beef..6718778 100644 --- a/Apps.Crowdin/Connections/OAuth/OAuth2TokenService.cs +++ b/Apps.Crowdin/Connections/OAuth/OAuth2TokenService.cs @@ -1,5 +1,6 @@ using Apps.Crowdin.Constants; using Blackbird.Applications.Sdk.Common; +using Blackbird.Applications.Sdk.Common.Authentication; using Blackbird.Applications.Sdk.Common.Authentication.OAuth2; using Blackbird.Applications.Sdk.Common.Invocation; using Newtonsoft.Json; @@ -7,7 +8,7 @@ namespace Apps.Crowdin.Connections.OAuth; public class OAuth2TokenService(InvocationContext invocationContext) - : BaseInvocable(invocationContext), IOAuth2TokenService + : BaseInvocable(invocationContext), IOAuth2TokenService, ITokenRefreshable { private const string ExpiresAtKeyName = "expires_at"; @@ -93,5 +94,18 @@ public bool IsRefreshToken(Dictionary values) => values.TryGetValue(ExpiresAtKeyName, out var expireValue) && DateTime.UtcNow > DateTime.Parse(expireValue); + public int? GetRefreshTokenExprireInMinutes(Dictionary values) + { + if (!values.TryGetValue(ExpiresAtKeyName, out var expireValue)) + return null; + + if (!DateTime.TryParse(expireValue, out var expireDate)) + return null; + + var difference = expireDate - DateTime.UtcNow; + + return (int) difference.TotalMinutes - 1; + } + #endregion } \ No newline at end of file