IdentityServer4 icon indicating copy to clipboard operation
IdentityServer4 copied to clipboard

IRedirectUriValidator

Open DiginessForever opened this issue 8 years ago • 7 comments

I created a custom class to validate redirectUris, implementing IRedirectUriValidator on my IdentityServer4 implementation.

In the IdentityServer4 startup in ConfigureServices, I have:

services.AddIdentityServer()
   .AddRedirectUriValidator<AuthorizedRedirectValidator>()

(the .AddRedirectUriValidator line is just one of the many sub functions called after AddIdentityServer())

I've tried putting the above in different orders, but regardless, when I run a client through the authentication, the above class that implements IRedirectUriValidator isn't getting called (it still calls the standard one).

Do I need to do anything else? I realize that implementing your own validator instead of doing an exact match can open you to covert redirects and have exacting safeguards in the validator.

DiginessForever avatar Feb 23 '18 14:02 DiginessForever

I've been playing with a client and its redirectUris and finally got the above to trigger. It seems though that the standard redirect validator is still running beforehand and rejecting any uris that aren't explicitly mentioned in the server side client config. Any way I can completely override it?

DiginessForever avatar Feb 23 '18 16:02 DiginessForever

It seems that without being explicitly in the allowed uris, it fails on the authorize endpoint and throws an error: (the below being run with minimal validation in the interface, only for debugging)

IdentityServer4.Endpoints.AuthorizeEndpoint:Information: { "ClientId": "myClient", "ClientName": "Custom Web Client", "AllowedRedirectUris": [ "https://localhost:44001" ], "SubjectId": "anonymous", "RequestedScopes": "", "Raw": { "client_id": "myClient", "redirect_uri": "https://localhost:44001/home", "response_mode": "form_post", "response_type": "code id_token", "scope": ... "state": "OpenIdConnect.AuthenticationProperties=... "nonce": ... } }

DiginessForever avatar Feb 23 '18 16:02 DiginessForever

I created a StackOverflow question as well:
https://stackoverflow.com/questions/48952192/identityserver4-redirect-validator-implementing-iredirecturi-interface

DiginessForever avatar Feb 23 '18 16:02 DiginessForever

It seems though that the standard redirect validator is still running beforehand and rejecting any uris that aren't explicitly mentioned in the server side client config. Any way I can completely override it?

I don't think your observation is correct - check our main repo, we use a custom validator there as well and it works as expected.

leastprivilege avatar Feb 24 '18 15:02 leastprivilege

FWIW, I believe I found the cause of @DiginessForever's issue. If the Client.RedirectUris property is not set, or is set to an empty collection, then the IRedirectUriValidator will not be invoked. There needs to be a value in Client.RedirectUris, even if it's a garbage one. See the Config.cs here: https://github.com/IdentityServer/IdentityServer4.Demo/blob/master/src/IdentityServer4Demo/Config.cs, where we can see "https://notused" used everywhere as the RedirectUri.

Greeng0 avatar Apr 12 '19 21:04 Greeng0

I've been trying to get this working too, and have found that AddRedirectUriValidator<...>() doesn't seem to work, but adding this line (like the demo project) was successful: services.AddTransient<IRedirectUriValidator, ...>();

EddyPPP avatar Sep 01 '19 16:09 EddyPPP

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

lock[bot] avatar Jan 10 '20 20:01 lock[bot]