Asp.net-Core

更改 IdentityServer 4 中的預設端點

  • December 19, 2020

我正在使用 IdentityServer 4 (1.0.0-beta5)。

預設情況下,身份驗證的端點是:’/connect/token’

如何更改 IdentityServer 中的預設端點,例如:’/api/login’?

謝謝

現在您無法更改協議端點的端點 URL。如果你認為這是必要的,請在 github 上打開一個問題。

一旦你在啟動時設置了 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 ,諸如TokenEndpointAuthorizeEndpoint類的端點就會在內部註冊- 當它呼叫AddDefaultEndPoints方法時。現在 Endpoint 在接收到每個請求以匹配請求的 Url 時進行迭代;因此更改路徑將立即生效。

請注意,在上面的範例中 - 我已經從任何以它為前綴的路徑中刪除了所有“/connect”值。

引用自:https://stackoverflow.com/questions/39186533