我正在研究 IdentityServer 4 (1.0.0-beta5)。
默认情况下,身份验证端点为:'/connect/token'。
如何更改 IdentityServer 中的默认端点,例如:“/api/login”?
谢谢
最佳答案
在启动时设置 Identity Server 4 后 - 您可以使用此“hack”并更新端点路径:
var builder = services.AddIdentityServer()
.AddDeveloperSigningCredential()
.AddInMemoryApiResources(Config.GetApiResources())
.AddInMemoryClients(Config.GetClients());
builder.Services
.Where(service => service.ServiceType == typeof(Endpoint))
.Select(item => (Endpoint)item.ImplementationInstance)
.ToList()
.ForEach(item => item.Path = item.Path.Value.Replace("/connect", ""));
基本上 - 一旦您调用AddIdentityServer,端点(例如TokenEndpoint)、AuthorizeEndpoint类就会在内部注册 - 当它调用AddDefaultEndPoints时em> 方法。现在,Endpoint 在收到每个请求时都会迭代以匹配请求的 Url;因此更改路径会立即生效。
Please note that in the above example - I have removed all the "/connect" values from any of the paths that were prefixed with it.
关于asp.net-core - 更改 IdentityServer 4 中的默认端点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39186533/