0

This seems to be a continuation of several issues I have posted questions about. I have an application that queries an eBay api for a user token when posting a refresh token. I created a test application in VB.Net where I supply the user refresh token to a form, the test app then runs a VB.NET routine which references RestSharp. The Client is created when the form opens in the test app and when the class is instanciated in the final app. This is to reuse the client for the remaining calls once I have a user token. Code below.

 Dim client As RestClient = New RestClient(sBaseURL)

 Async Sub cmdGetCode_Click(sender As Object, e As EventArgs) Handles cmdGetCode.Click
        Dim Base64Auth As String = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(ClientID & ":" & ClientSec))
        Dim request As RestRequest = New RestRequest(sTokURL, Method.Post)
        With request
            .AddHeader("Content-Type", "application/x-www-form-urlencoded")
            .AddHeader("Authorization", "Basic " & Base64Auth)
            .AddParameter("grant_type", "refresh_token")
            .AddParameter("refresh_token", txtRefreshToken.Text)
            .AddParameter("Scope", "https://api.ebay.com/oauth/api_scope/sell.inventory")
        End With
        Try
            Dim response = Await client.PostAsync(request)
            'Dim responce = Await client.ExecuteAsync(request)
            If response.StatusCode = HttpStatusCode.OK Then
                Dim sR As String = response.Content
                'uT = JsonSerializer.Deserialize(Of userToken)(sR)
                uT = New userToken
                JsonConvert.PopulateObject(sR, uT)
                txtAuthToken.Text = uT.access_token.ToString
                txtDuration.Text = uT.expires_in.ToString
            Else
                txtRefreshToken.Text = "Failed to GetType tokens"
            End If
        Catch ex As Exception
            txtRefreshToken.Text = "Failed to GetType tokens"
        End Try
    End Sub

This works. I monitor with Fiddler and it connects with api.ebay.com and establishes a tunnel to communicate over.

I use the same routine in the final application but it does not establish the communication tunnel when monitored using Fiddler. The only difference I can see from the Fiddler connection session properties is the failing one does not appear to be using TLS 1.2. The successful call has FLAGS

== FLAGS ==================
BitFlags: [ResponseGeneratedByFiddler, IsDecryptingTunnel] 0x2100
HTTPS-CLIENT-SESSIONID: empty
HTTPS-CLIENT-SNIHOSTNAME: api.ebay.com
HTTPS-CLIENT-VERSION: Tls12
HTTPS-SERVER-CIPHER: Aes128 128bits
HTTPS-SERVER-VERSION: Tls12
X-CLIENTIP: 127.0.0.1
X-CLIENTPORT: 50237
X-EGRESSPORT: 50238
X-HOSTIP: 209.140.129.40
X-PROCESSINFO: testrestsharp:21184
X-RESPONSEBODYTRANSFERLENGTH: 0

The unsuccessful call returns flags

== FLAGS ==================
BitFlags: [ResponseGeneratedByFiddler] 0x100
X-CLIENTIP: 127.0.0.1
X-CLIENTPORT: 50298
X-EGRESSPORT: 50302
X-HOSTIP: 209.140.129.40
X-PROCESSINFO: getpolicies:24828
X-RESPONSEBODYTRANSFERLENGTH: 0

I am at a loss. Both applications are using the same eBay url and the same input variables. Any thoughts on what is going on would be appreciated. Both of these applications are being run on the same computer.

DougM
  • 109
  • 3
  • 16
  • 1
    We had similar issues in our environment. Ended up adding this where required to force 1.2: `ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;` Also make sure you're using framework 4.7.2 or upwards. Also have a look at which framework is specified in app.config. – Andrew Mortimer May 24 '22 at 04:49
  • Possibly useful: https://stackoverflow.com/questions/45382254/update-net-web-service-to-use-tls-1-2 – Andrew Mortimer May 24 '22 at 04:50
  • 100% with Andrew on this. Make sure you're targeting a framework version that supports TLS1.2 – Hursey May 24 '22 at 05:24
  • There is something odd going on here I don't understand. I copied the Windows form over from my test project into my application and set it as the start object. Previously I had start set to a procedure. When I run with the form the RestSharp api call works orrectly. Same code, just a different type of class module. I am using framework 4.7.2 and added the ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 statement. – DougM May 24 '22 at 16:35

0 Answers0