2

I have a Windows application that is using the "password" grant type. It is able to authenticate to the Identityserver4 without SSL, but not with SSL. The problem is that it is giving an error:

The underlying connection was closed: An unexpected error occurred on a send

I tried it from postman, and it worked, but not from my Windows Application. Below is the code:

            var tokenClient = new TokenClient($"{IdentityServer}/connect/token", Constants.ClientId, Constants.ClientSecret);
        var tokenResponseTask = tokenClient.RequestResourceOwnerPasswordAsync(username, password, Constants.Scope);
        tokenResponseTask.Wait();
        return tokenResponseTask.Result;

Below also is another code the I tried, but it doesn't work:

 TokenResponse tokenResponse;

        string request = $"client_id={clientId}&client_secret={clientSecret}&grant_type={grantType}&scope={scope}&username={username}&password={password}";

        using (var client = new WebClient())
        {
            client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
            byte[] result = client.UploadData(endpointUrl, "POST", Encoding.UTF8.GetBytes(request));
            string resultJson = Encoding.UTF8.GetString(result, 0, result.Length);

            tokenResponse = JsonConvert.DeserializeObject<TokenResponse>(resultJson);
        }
The Eagle
  • 427
  • 1
  • 4
  • 13
  • There is very little information in this question. Add the code that you are using to login and what version of .NET are you using for the windows application? –  Jul 21 '18 at 16:32
  • Finally, I found the solution under the following link: https://stackoverflow.com/questions/30664566/authentication-failed-because-remote-party-has-closed-the-transport-stream – The Eagle Jul 26 '18 at 06:02
  • Finally, I found the solution under the following link: https://stackoverflow.com/questions/30664566/authentication-failed-because-remote-party-has-closed-the-transport-stream – The Eagle Jul 26 '18 at 06:03
  • I found out the solution under the following link: https://stackoverflow.com/questions/30664566/authentication-failed-because-remote-party-has-closed-the-transport-stream – The Eagle Jul 26 '18 at 06:05

2 Answers2

1

Finally, I was able to find the solution under the following link:

Authentication failed because remote party has closed the transport stream

The Eagle
  • 427
  • 1
  • 4
  • 13
0

'The underlying connection was closed' error is often seen when the SSL handshake fails. SSL handshake failure usually has something to do with the relevant SSL certificate and whether or not the certificate is trusted.

Check ...

  1. Whether IdentityServer is configured to run under HTTP and HTTPS.
  2. Your Windows Application is correctly configured for SSL.
  3. Test some of the IdentityServer endpoints using a browser with the https protocol.

Hope this gets you going on a helpful investigation path.

Simon
  • 136
  • 1
  • 3