Search code examples
identityserver4

Where can I see default routes in IdentityServer4?


I use is4aspid template for IdentityServer4. When the server receives a request connect/authorize, called AccountController.Login. Question. Where i might see all default routing? Example for logout? And can i change this? Example, when receives a "connect/authorize", called OtherControl.MyLogin?


Solution

  • Where i might see all default routing?

    There is a discovery endpoint that is used to retrieve metadata about your IdentityServer.

    It returns information like the issuer name, key material, supported scopes etc... and you can see the endpoints (token endpoint, userinfo endpoint, etc) there.

    When you run your IdentityServer application the discovery endpoint is available via /.well-known/openid-configuration relative to the base address, e.g.:

    http://youridentityserver/.well-known/openid-configuration
    

    Example for logout?

    "end_session_endpoint": "http://youridentityserver/connect/endsession",
    

    And can i change this?

    You cannot change the discovery endpoint URL, it is according on the spec.

    Edit


    But where can I read the official documentation about this? And can I change this behavior?

    Researching about the documentation I could found that you can use the UserInteraction options to reconfigure the routes (I agree that it should be better documented).

    It means that you can set your own url (for LoginUrl, LogoutUrl, ConsentUrl, ErrorUrl) to redirect the user.

    For example:

    I developed a .Net Core application that redirects the user to a /Account/Login route according with the default identityserver4 configuration.

    I want to redirect the user to Test/NewLogin route for user login. So, using the UserInteraction I can reconfigure the LoginUrl the in Startup.cs class.

    Solution 1: Adding in a SetupIdentityServer options method

    public void ConfigureServices(IServiceCollection services)
    {
        IIdentityServerBuilder builder = services.AddIdentityServer(SetupIdentityServer)
        ...
    }
    

    Below is the implementation of the SetupIdentityServer method:

    private static void SetupIdentityServer(IdentityServer4.Configuration.IdentityServerOptions identityServerOptions)
    {
        identityServerOptions.UserInteraction.LoginUrl = "/Test/NewLogin";
    }
    

    Solution 2: I can achieve the same result with this code

    public void ConfigureServices(IServiceCollection services)
    {
       IIdentityServerBuilder builder = services.AddIdentityServer(options => options.UserInteraction.LoginUrl = "/Test/NewLogin"))
       ...
    }
    

    Result:

    enter image description here