我开发的认证服务器提供的令牌被用来消耗使用IdentityServer4我们的API。 我正在使用MongoDB作为数据库,我让用户可以获取令牌,并且更安全我正在使用自定义证书来加密令牌。 这是我Startup.cs我AuthenticationServer
的的样子:身份服务器4 - 禁用发现端点
public void ConfigureServices(IServiceCollection services)
{
services.Configure<AppSettings>(Configuration.GetSection("AppSettings"));
var cert = new X509Certificate2(Path.Combine(_environment.ContentRootPath, "cert", "whatever.pfx"), "whatever");
services.AddIdentityServer().AddSigningCredential(cert)
.AddInMemoryApiResources(Config.Config.GetApiResources());
services.AddTransient<IUserRepository, UserRepository>();
services.AddTransient<IClientStore, ClientStore>();
services.AddTransient<IProfileService, UserProfileService>();
services.AddTransient<IResourceOwnerPasswordValidator, UserResourceOwnerPasswordValidator>();
services.AddTransient<IPasswordHasher<User.Model.User>, PasswordHasher<User.Model.User>>();
}
正如你可以看到我有那些做客户端身份验证和密码验证界面的自定义实现。这工作正常。
然后我保护另一个应用程序与生成的令牌,我也有定义的,它必须使用IdentityServerAuthetication
(本地主机:5020是我的AuthenticationServer
运行)
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
app.UseCors("CorsPolicy");
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
{
Authority = "http://localhost:5020",
RequireHttpsMetadata = false,
ApiName = "MyAPI",
RoleClaimType = JwtClaimTypes.Role
});
app.UseMvc();
}
一切工作正常,但如果我关闭AuthenticationServer
然后我从我保护API此错误:
System.InvalidOperationException:IDX10803:无法从获得的配置:'http://localhost:5020/.well-known/openid-configuration'。 at Microsoft.IdentityModel.Protocols.ConfigurationManager`1.d__24.MoveNext() ---从以前的位置抛出异常的堆栈跟踪结束--- 在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务) 在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务的任务) 在Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler.d__1.MoveNext() 失败:Microsoft.AspNetCore.Server.Kestrel [13]
因此,API看起来是发现端点,看看端点在哪里解密令牌(我想这将是userinfo_endpoint
)。
我的观点是:
- 看来,发现端点用来获取如何使用认证服务器信息(对我来说是有道理的,开放的API),但是对我们来说,我们不发展和开放的API,所以我们的客户将只是我们已经达成的协议,我们会提前告诉他们端点,我们很可能会限制IP地址。
- 有什么办法停用发现端点和设置的API证书正确地解密令牌。
也许我错过了整个图片,我说的是愚蠢的事情,但我很乐意了解背后的概念。 在此先感谢
这是否意味着拥有可用的发现端点不会造成安全风险? ..我来自WCF,我不得不禁用端点的元数据。 – Learner