docusign / docusign-esign-csharp-client

The Official Docusign C# Client Library used to interact with the eSignature REST API. Send, sign, and approve documents using this client.
https://developers.docusign.com/docs/esign-rest-api/sdks/csharp/
MIT License
129 stars 159 forks source link

Newtonsoft.Json versioning issue while attempting to authenticate with JWT using DocuSign.eSign #364

Closed ha-cmhheli closed 2 months ago

ha-cmhheli commented 2 years ago

Not sure what I'm doing wrong if anything but I can't get basic JWT authentication working with the latest package Scenario: .NET 4.7.2 c# Test project Using DocuSign.eSign.dll v5.9.0 No other nuget packages added Very simple test method.
This line: ApiClient apiClient = new ApiClient(@"https://www.docusign.net/restapi"); appears to need Newtonsoft.Json v11.0.2 This line: OAuthToken authToken = apiClient.RequestJWTUserToken(clientId, userId, oathPath, Encoding.UTF8.GetBytes(rsaKey), expiresIn1Hour, scopes); appears to need Newtonsoft.Json v10.0.0.0

[TestMethod]

    public void TestAuth()
    {
        string clientId = ""; // removed for issue
        string userId = ""; // removed for issue
        string oathPath = @"https://account.docusign.com/oauth/auth";

        ApiClient apiClient = new ApiClient(@"https://www.docusign.net/restapi");

        int expiresIn1Hour = 1;
        string rsaPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "RSAPrivateKey.txt");
        string rsaKey = System.IO.File.ReadAllText(rsaPath);
        var scopes = new List<string> { "signature" };

        OAuthToken authToken = apiClient.RequestJWTUserToken(clientId, userId, oathPath, Encoding.UTF8.GetBytes(rsaKey), expiresIn1Hour, scopes);

        Assert.IsNotNull(authToken);
    }

Error: System.TypeInitializationException HResult=0x80131534 Message=The type initializer for 'System.IdentityModel.Tokens.Jwt.JsonExtensions' threw an exception. Source=System.IdentityModel.Tokens.Jwt StackTrace: at System.IdentityModel.Tokens.Jwt.JsonExtensions.SerializeToJson(Object value) at System.IdentityModel.Tokens.Jwt.JwtHeader.SerializeToJson() at System.IdentityModel.Tokens.Jwt.JwtHeader.Base64UrlEncode() at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.CreateJwtSecurityTokenPrivate(String issuer, String audience, ClaimsIdentity subject, Nullable1 notBefore, Nullable1 expires, Nullable1 issuedAt, SigningCredentials signingCredentials, EncryptingCredentials encryptingCredentials) at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.CreateToken(SecurityTokenDescriptor tokenDescriptor) at DocuSign.eSign.Client.ApiClient.RequestJWTUserToken(String clientId, String userId, String oauthBasePath, Byte[] privateKeyBytes, Int32 expiresInHours, List1 scopes) at CMHInc.DocuSign.Test.DocuSignClientTest.TestBasic() in C:\Users\harmitage\source\repos\Reservations\CMHInc.DocuSign.Test\DocuSignClientTest.cs:line 85

This exception was originally thrown at this call stack:

Inner Exception 1: FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

aardvark79 commented 2 years ago

I am having the same issue, except I'm on .NET 5, and with the same DocuSign.eSign.dll version as you (5.9.0), mine is complaining that it can't find Newtonsoft.Json, Version=11.0.0.0. I did go ahead and install the Newtonsoft.Json nuget package, which did not work. I also tried adding a binding redirect for it in web.config and that also did not work.

kenharris commented 2 years ago

I'm Ken, a Software Developer at Docusign.

I wanted to reach out to see if you're still experiencing this issue. I haven't been able to reproduce it in a .NET 4.7.2 test project using the 5.9.0 version of the eSign NuGet package. Using the code snipped that you provided, my test method compiles and completes successfully in Visual Studio 2022. The only NuGet package added to my test project was the eSign NuGet package and my test project has only the one test method.

Which version of Visual Studio are you using? Also, are there any other dependencies in your test project?

ha-cmhheli commented 2 years ago

Hi, This issue has been resolved with binding redirects in the config file. Thanks, Heather

From: Ken Harris @.> Sent: April 11, 2022 9:31 AM To: docusign/docusign-esign-csharp-client @.> Cc: Heather Armitage (CMH) @.>; Author @.> Subject: Re: [docusign/docusign-esign-csharp-client] Newtonsoft.Json versioning issue while attempting to authenticate with JWT using DocuSign.eSign (Issue #364)

You don't often get email from @.**@.>. Learn why this is importanthttp://aka.ms/LearnAboutSenderIdentification NOTICE: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender.

I'm Ken, a Software Developer at Docusign.

I wanted to reach out to see if you're still experiencing this issue. I haven't been able to reproduce it in a .NET 4.7.2 test project using the 5.9.0 version of the eSign NuGet package. Using the code snipped that you provided, my test method compiles and completes successfully in Visual Studio 2022. The only NuGet package added to my test project was the eSign NuGet package and my test project has only the one test method.

Which version of Visual Studio are you using? Also, are there any other dependencies in your test project?

- Reply to this email directly, view it on GitHubhttps://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fdocusign%2Fdocusign-esign-csharp-client%2Fissues%2F364%23issuecomment-1095201244&data=04%7C01%7Charmitage%40cmhheli.com%7C2f501049267849721b8f08da1bd048d8%7Cbb43b24f11394bd9821c6cebb99a16cf%7C0%7C0%7C637852878652100236%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=TEdggBr%2B1es%2Fzzjnap6dtNX7jlg0rfLAd1aYgr8NH3A%3D&reserved=0, or unsubscribehttps://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAYEJXRX3BQU7VAB2XAFEAYTVERATJANCNFSM5QKBMKUA&data=04%7C01%7Charmitage%40cmhheli.com%7C2f501049267849721b8f08da1bd048d8%7Cbb43b24f11394bd9821c6cebb99a16cf%7C0%7C0%7C637852878652256477%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=MxnbLlPzFXr008Bqw0qGqqFUO9S1Lga%2BSB%2BwOT%2BrnnA%3D&reserved=0. You are receiving this because you authored the thread.Message ID: @.**@.>>

avinfinity commented 2 months ago

As confirmed in previous thread, this issue is not more happening. Hence closing this issue. Thanks