Adding custom endpoint to IdentityServer4

IdentityServer 4 Mar 06, 2020
  • Firstly, setup an IdentityServer project, open up the command line and paste these commands:
dotnet new -i IdentityServer4.Templates
md quickstart
cd quickstart
md src
cd src
dotnet new is4empty -n IdentityServer
dotnet new is4ui -n IdentityServer
cd ..
dotnet new sln -n Quickstart
dotnet sln add .\src\IdentityServer\IdentityServer.csproj
Command Line

  • The next step is to build and run the solution correctly as following:
Home Page

  • Add your custom controller to project:
[Route("customapi")]
public class CustomApiController : ControllerBase
{
    public IActionResult Get()
    {
        // omitted
    }
}
CustomApiController.cs

  • Add your endpoint to the discovery document, like this:
services.AddIdentityServer(options =>
{
    options.Discovery.CustomEntries.Add("custom_api", "~/customapi");
})
Startup.cs

  • Finally, run the project and now you can see your custom endpoint on the discovery document:
Discovery Document

Tags

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.