我正在使用身份服务器4身份验证来开发我的api。
http://localhost:9626/ 的网址正常工作,我可以生成令牌。但 http://192.168.1.7:9626 我无法访问的授权网址。
我遇到此错误。
连接到http://192.168.1.7:9626/.well-known/openid-configuration时出错:需要HTTPS
令牌生成代码。
using (var httpClientHandler = new HttpClientHandler())
{
httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) =>
{
return true;
};
var client = new HttpClient(httpClientHandler);
var disco = client.GetDiscoveryDocumentAsync(ConfigHelper.AppSettings["Auth:ServerURL"]).Result;
if (disco.IsError) throw new Exception(disco.Error);
var response = client.RequestPasswordTokenAsync(new PasswordTokenRequest
{
Address = disco.TokenEndpoint,
ClientId = ConfigHelper.AppSettings["Auth:ClientId"],
ClientSecret = ConfigHelper.AppSettings["Auth:ClientSecret"],
UserName = model.UserName,
Password = model.Password,
Scope = ConfigHelper.AppSettings["Auth:AllowScopes"]
}).Result;
if (response.IsError) return StatusCode(StatusCodes.Status500InternalServerError, response.Error);
var handler = new JwtSecurityTokenHandler();
var tokenS = handler.ReadToken(response.AccessToken) as JwtSecurityToken;
Startup.cs配置
// identity server certificate configuration
var fileName = Path.Combine(_env.ContentRootPath, "localhost.pfx");
if (!File.Exists(fileName))
{
throw new FileNotFoundException("Signing Certificate is missing!");
}
var cert = new X509Certificate2(fileName,"test@123");
services.AddIdentityServer().AddSigningCredential(cert)
.AddInMemoryApiResources(AuthConfiguration.GetApiResources())
.AddInMemoryClients(AuthConfiguration.GetClients()).AddResourceOwnerValidator<ResourceOwnerPasswordValidator>().AddProfileService<ProfileService>();
这是我通过此工具 DigiCertUtil 生成的localhost.pfx文件。
https://github.com/IdentityServer/IdentityServer4/issues/1116我引用了此链接。我没有明确的解决方案,他们说这可能是证书错误。 同样的事情意味着我需要做的事。...