我開發的認證服務器提供的令牌被用來消耗使用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