signnow / SignNow.NET

SignNow.Net is the official .NET 4.5+ and .NET Standard class library for the SignNow API. SignNow allows you to embed legally-binding e-signatures into your app, CRM or cloud storage. Send documents for signature directly from your website. Invite multiple signers to finalize contracts.
https://www.signnow.com/developers
MIT License
16 stars 12 forks source link

error invalid_token #128

Closed NechamaMiller closed 3 years ago

NechamaMiller commented 3 years ago

I am trying to call GetDocumentAsync using the following code:

    `Dim docId = "a561139515f0486ea3643fc7051ab8b6393c091f"
    Dim accessToken = xxx
    Dim tkn = New Token With {
                       .AccessToken = accessToken
                       }

    Dim ctx As New SignNowContext(tkn)

    Dim svc = New OAuth2Service(clientKey, secretKey)

    Dim valid As Boolean = svc.ValidateTokenAsync(tkn).GetAwaiter().GetResult()

    Console.WriteLine("Valid? " & valid)

    Try
        Dim doc As SignNowDocument = ctx.Documents.GetDocumentAsync(docId).GetAwaiter().GetResult()
    Catch ex As Exception
        Console.WriteLine(ex)
    End Try`

This is the output that I get:

Valid? True SignNow.Net.Exceptions.SignNowException: invalid_token at SignNow.Net.Internal.Service.SignNowClient.d14.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at SignNow.Net.Internal.Service.SignNowClient.d121.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at SignNow.Net.Internal.Service.SignNowClient.<RequestAsync>d__101.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at SignNow.Net.Service.DocumentService.d__3.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at EsignNewApiTest.Module1.Test() in C:\Users\pc\source\repos\EsignNewApiTest\EsignNewApiTest\Module1.vb:line 29

As you can see, the token is validating properly, but I still get an error invalid_token when I try to get the document. I reached out to your support team by email but they were not able to help me. Can you tell me why this does not work and what I can do to make this work?

I cannot get the token using username and password because I am submitting this for a 3rd party. They log in on the front end, I save the token in the database, and then I need to use it in a back-end process to send to SignNow

AlexNDRmac commented 3 years ago

Hi @NechamaMiller. In your example you are making one simple mistake - manually creating the Token object. In this case, you have invalid_token because you are not setting a token type property. To avoid this situation, you should use the following:

Dim tkn = New Token With {
                       .AccessToken = accessToken,
                       .TokenType = TokenType.Bearer
                       }
NechamaMiller commented 3 years ago

Thank you! That worked