无法使用SSL从Windows应用程序连接到IdentityServer 4
我有一个使用“密码”授权类型的Windows应用程序。它能够在不使用无法使用SSL从Windows应用程序连接到IdentityServer 4,ssl,identityserver4,Ssl,Identityserver4,我有一个使用“密码”授权类型的Windows应用程序。它能够在不使用SSL的情况下对IdentityServer 4进行身份验证,但不能使用SSL进行身份验证。问题是它给出了一个错误: The underlying connection was closed: An unexpected error occurred on a send 我从邮递员那里试过,它成功了,但在我的Windows应用程序中没有。代码如下: var tokenClient = new Token
SSL
的情况下对IdentityServer 4进行身份验证,但不能使用SSL
进行身份验证。问题是它给出了一个错误:
The underlying connection was closed: An unexpected error occurred on a send
我从邮递员那里试过,它成功了,但在我的Windows应用程序中没有。代码如下:
var tokenClient = new TokenClient($"{IdentityServer}/connect/token", Constants.ClientId, Constants.ClientSecret);
var tokenResponseTask = tokenClient.RequestResourceOwnerPasswordAsync(username, password, Constants.Scope);
tokenResponseTask.Wait();
return tokenResponseTask.Result;
下面是我尝试过的另一个代码,但它不起作用:
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);
}
TokenResponse-TokenResponse;
string request=$“client_id={clientId}&client_secret={clientSecret}&grant_type={grantType}&scope={scope}&username={username}&password={password}”;
使用(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(resultJson);
}
当SSL握手失败时,通常会出现“基础连接已关闭”错误。
SSL握手失败通常与相关SSL证书以及证书是否可信有关
检查
IdentityServer是否配置为在HTTP和HTTPS下运行
您的Windows应用程序已正确配置为SSL
使用带有https协议的浏览器测试某些IdentityServer端点
希望这能让你走上一条有用的调查之路。最后,我通过以下链接找到了解决方案:
关于这个问题的信息很少。添加您用于登录的代码以及windows应用程序使用的.NET版本?最后,我在以下链接下找到了解决方案:最后,我在以下链接下找到了解决方案:我在以下链接下找到了解决方案:谢谢@Simon,我更新了我的初始问题,请检查。