Skip to content

Commit

Permalink
Issue #19 - NuGet package JWT replaced with package jose-jwt (has…
Browse files Browse the repository at this point in the history
… better .NET 4.5 support).
  • Loading branch information
OlegRa committed Nov 14, 2019
1 parent 13cd97e commit 100233f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 36 deletions.
32 changes: 8 additions & 24 deletions ILovePDF/ILovePDF/Core/RequestHelper.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using JWT;
using JWT.Algorithms;
using JWT.Serializers;
using LovePdf.Model.Enums;
using LovePdf.Model.Enums;
using LovePdf.Model.Exception;
using LovePdf.Model.TaskParams;
using Newtonsoft.Json;
Expand All @@ -16,13 +13,15 @@
using System.Net.Http;
using System.Net.Http.Headers;
using System.Security.Authentication;
using System.Text;
using System.Threading.Tasks;
using Jose;

namespace LovePdf.Core
{
internal class RequestHelper
{
private string _privateKey;
private byte[] _privateKey;
private string _publicKey;
private readonly short _jwtDelay = 5400;

Expand Down Expand Up @@ -571,7 +570,7 @@ private static List<byte[]> ToChunks(Stream fileStream)

public RequestHelper SetKeys(string privateKey, string publicKey)
{
_privateKey = privateKey;
_privateKey = Encoding.UTF8.GetBytes(privateKey);
_publicKey = publicKey;
return this;
}
Expand Down Expand Up @@ -620,20 +619,10 @@ private bool IsExpiredGwt()
{
try
{
IJsonSerializer serializer = new JsonNetSerializer();
IDateTimeProvider provider = new UtcDateTimeProvider();
IJwtValidator validator = new JwtValidator(serializer, provider);
IBase64UrlEncoder urlEncoder = new JwtBase64UrlEncoder();
IJwtDecoder decoder = new JwtDecoder(serializer, validator, urlEncoder);

var json = decoder.Decode(Gwt, _privateKey, verify: true);
JWT.Decode(Gwt, _privateKey, JwsAlgorithm.HS256);
return false;
}
catch (TokenExpiredException)
{
return true;
}
catch (SignatureVerificationException)
catch (Exception)
{
return true;
}
Expand Down Expand Up @@ -665,12 +654,7 @@ private string GetJwt()
payLoad.Add("file_encryption_key", EncryptKey);
}

IJwtAlgorithm algorithm = new HMACSHA256Algorithm();
IJsonSerializer serializer = new JsonNetSerializer();
IBase64UrlEncoder urlEncoder = new JwtBase64UrlEncoder();
IJwtEncoder encoder = new JwtEncoder(algorithm, serializer, urlEncoder);

var token = encoder.Encode(payLoad, _privateKey);
var token = JWT.Encode(payLoad, _privateKey, JwsAlgorithm.HS256);

return token;
}
Expand Down
11 changes: 2 additions & 9 deletions ILovePDF/ILovePDF/ILovePDF.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,10 @@
<PropertyGroup>
<AssemblyOriginatorKeyFile>iLovePdf.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
<PackageReference Include="JWT" Version="3.0.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net46' ">
<PackageReference Include="JWT" Version="5.3.1" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="jose-jwt" Version="2.5.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions ILovePDF/Tests/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
<ItemGroup>
<PackageReference Include="MSTest.TestAdapter" Version="1.1.11" />
<PackageReference Include="MSTest.TestFramework" Version="1.1.11" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.0.0" />
<PackageReference Include="MSTest.TestFramework" Version="2.0.0" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.Net.Http" />
Expand Down

0 comments on commit 100233f

Please sign in to comment.