skoruba / IdentityServer4.Admin

The administration for the IdentityServer4 and Asp.Net Core Identity
MIT License
3.57k stars 1.15k forks source link

Only force the Redirect Uri on Admin.UI on OpenIdConnect Auth when explicitly defined on configuration #842

Open cjaliaga opened 3 years ago

cjaliaga commented 3 years ago

Currently we are modifying the Redirect Uri when authenticating using the OpenIdConnect provider with a value defined in configuration:

https://github.com/skoruba/IdentityServer4.Admin/blob/7023c0c6bb86f0d3c9bd2a5f603d17984c5c5fe3/src/Skoruba.IdentityServer4.Admin.UI/Helpers/StartupHelpers.cs#L420-L425

By default the OpenIdConnect provider is able to generate the callback URL based on the current hostname, port, etc:

https://github.com/dotnet/aspnetcore/blob/b7a2ec8c7ed6b48857af0a69688a73e8c14fe6cb/src/Security/Authentication/OpenIdConnect/src/OpenIdConnectHandler.cs#L378

Now that we have the UI as a NuGet package, is not possible anymore to remove that behavior and let the OpenIdConnect provider generate the callback for you so you need to forcibly add that value.

We should only set that property if the user is trying to override the default, example:

private static Task OnRedirectToIdentityProvider(RedirectContext context, AdminConfiguration adminConfiguration)
{
    if(!string.IsNullOrEmpty(adminConfiguration.IdentityAdminRedirectUri))
    {
        context.ProtocolMessage.RedirectUri = adminConfiguration.IdentityAdminRedirectUri;
    }

    return Task.CompletedTask;
}

What do you think @skoruba? I can open a quick PR with this if you agree.

Thanks!

skoruba commented 3 years ago

Hey @cjaliaga - this is a good idea, could you please send a PR? 😊