Skip to content

Commit

Permalink
Issue #28 - fixed problem with the missed JWT expiration time checking.
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegRa committed Sep 28, 2020
1 parent 037dbea commit e0583a0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 6 additions & 2 deletions ILovePDF/ILovePDF/Core/RequestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ namespace LovePdf.Core
{
internal class RequestHelper
{
private static readonly DateTime epoch =
new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);

private static RequestHelper _instance;
private readonly Int16 _jwtDelay = 5400;
private Byte[] _privateKey;
Expand Down Expand Up @@ -614,7 +617,9 @@ private Boolean isExpiredGwt()
try
{
JWT.Decode(Gwt, _privateKey, JwsAlgorithm.HS256);
return false;
var expired = epoch.AddSeconds(
(JObject.Parse(JWT.Payload(Gwt))["exp"] ?? 0).Value<double>());
return expired > DateTime.UtcNow;
}
catch (Exception)
{
Expand All @@ -628,7 +633,6 @@ private Boolean isExpiredGwt()
/// <returns></returns>
private String getJwt()
{
var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
var payLoad = new Dictionary<String, Object>
{
{"iss", ""},
Expand Down
4 changes: 1 addition & 3 deletions ILovePDF/ILovePDF/ILovePDF.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<OutputPath>bin\$(Configuration)\</OutputPath>
<Authors>Mario Martinez, Alexandra Kyluk, Aleksey Sidorov, Egor Krivoshapka</Authors>
<PackageId>ILove_PDF</PackageId>
<PackageLicenseUrl></PackageLicenseUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/ilovepdf/ilovepdf-net</PackageProjectUrl>
<PackageReleaseNotes>- Fixed problem with the incorrect API endpoint used for tasks chaining in the `Next` method.</PackageReleaseNotes>
<PackageTags>ILOVEPDF Merge PDF Split convert Office to pdf PDf JPG Images unlock Pdf repair rotate pdf</PackageTags>
Expand All @@ -25,7 +25,6 @@
<DebugType>full</DebugType>
<DocumentationFile>bin\$(Configuration)\ILovePdf.xml</DocumentationFile>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<RunCodeAnalysis>true</RunCodeAnalysis>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
Expand All @@ -35,7 +34,6 @@
<PropertyGroup>
<AssemblyOriginatorKeyFile>iLovePdf.snk</AssemblyOriginatorKeyFile>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit e0583a0

Please sign in to comment.