Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Apps.Crowdin/Apps.Crowdin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Nullable>enable</Nullable>
<Product>Crowdin</Product>
<Description>Cloud-based solution that streamlines localization management</Description>
<Version>1.2.36</Version>
<Version>1.2.37</Version>
<AssemblyName>Apps.Crowdin</AssemblyName>
</PropertyGroup>
<ItemGroup>
Expand Down
16 changes: 15 additions & 1 deletion Apps.Crowdin/Connections/OAuth/OAuth2TokenService.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
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;

namespace Apps.Crowdin.Connections.OAuth;

public class OAuth2TokenService(InvocationContext invocationContext)
: BaseInvocable(invocationContext), IOAuth2TokenService
: BaseInvocable(invocationContext), IOAuth2TokenService, ITokenRefreshable
{
private const string ExpiresAtKeyName = "expires_at";

Expand Down Expand Up @@ -93,5 +94,18 @@ public bool IsRefreshToken(Dictionary<string, string> values)
=> values.TryGetValue(ExpiresAtKeyName, out var expireValue) &&
DateTime.UtcNow > DateTime.Parse(expireValue);

public int? GetRefreshTokenExprireInMinutes(Dictionary<string, string> 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
}