asp.net-core - 在 MAC 上使用 IdentityServer 4 时无法访问 API
问题描述
我有 2 个使用 Identity Server 4 的 ASP.NET Core 2.1 应用程序(Auth 和 API)。
在 API 应用程序启动时,我有以下内容:
services
.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddIdentityServerAuthentication(x =>
x.ApiName = "api";
x.Authority = "https://localhost:5005";
x.RequireHttpsMetadata = false;
});
在 Auth 应用程序启动时,我有以下配置:
services
.AddIdentityServer()
.AddDeveloperSigningCredential()
.AddInMemoryIdentityResources(Config.GetIdentityResources())
.AddInMemoryApiResources(Config.GetApiResources())
.AddInMemoryClients(Config.GetClients())
.AddTestUsers(Config.GetTestUsers());
其中 Config 类如下:
public class Config {
public static List<ApiResource> GetApiResources() {
return new List<ApiResource> {
new ApiResource("api", "API Resource")
};
}
public static List<IdentityResource> GetIdentityResources() {
return new List<IdentityResource> {
new IdentityResources.OpenId(),
new IdentityResources.Profile()
};
}
public static List<Client> GetClients() {
return new List<Client> {
new Client {
ClientId = "app",
ClientName = "APP Client",
ClientSecrets = { new Secret("pass".Sha256()) },
AllowedGrantTypes = GrantTypes.ClientCredentials,
AllowedScopes = {
"api"
}
}
}
public static List<TestUser> GetTestUsers() {
return new List<TestUser> {
new TestUser {
SubjectId = "1",
Username = "john",
Password = "john",
Claims = new List<Claim> { new Claim("name", "John") } },
};
}
}
使用 Postman,我可以访问.well-known/openid-configuration
并创建访问令牌。
但是,当我调用 API 时,出现以下错误:
Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler[3]
Exception occurred while processing message.
System.InvalidOperationException: IDX20803: Unable to obtain configuration from: '[PII is hidden by default.
Set the 'ShowPII' flag in IdentityModelEventSource.cs to true to reveal it.]'. ---> System.IO.IOException: IDX20804: Unable to retrieve document from: '[PII is hidden by default.
Set the 'ShowPII' flag in IdentityModelEventSource.cs to true to reveal it.]'. ---> System.Net.Http.HttpRequestException:
The SSL connection could not be established, see inner exception. ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.
我跑dotnet dev-certs https --trust;
了,本地证书出现在 Mac 钥匙串上。
重要
在 Windows 计算机上,我发布的代码可以正常工作。
我能够访问.well-known/openid-configuration
和 API 端点。
我错过了什么?
解决方案
推荐阅读
- machine-learning - 测试误差小于训练误差
- python - 尝试使用 BeautifulSoup 访问 XML 中的嵌套元素
- react-native - 如何在方向更改时隐藏 React Native BottomTabNavigator(来自 React Navigation)?
- typescript - TypeScript 构造函数重载返回不同的类型
- apache-spark - 在 Pyspark 中按列使用 Windows 分区时排除列中的空值
- android - Gradle(v4.8)项目同步失败android studio
- python - Python 3.6.1 中的相对导入期间出错
- apache-kafka - Kafka Streams:在重新平衡期间存储状态
- javascript - 设备主体内容无法缩放以匹配视口的宽度
- ui-automation - 什么决定了通用 XAML 控件的哪一部分可以通过 UIAutomation 访问