Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OWIN OpenIdConnect middleware - set RedirectUri dynamically

Is there any way how can I set RedirectUri property for OpenIdConnectMessage based on a Request scope, not Application scope?

My app is serving multiple domains (myapp.com, myapp.fr, ..) and based on domain, it determine default language for the content. I need that the user is taken back to the same domain after login thru IdP so I need to find a way how RedirectUri is set per request scope rather than app scope as done by configuring middleware options in startup.cs .

like image 788
Antonin Jelinek Avatar asked Jun 04 '15 13:06

Antonin Jelinek


2 Answers

If you're using ResponseType = OpenIdConnectResponseType.CodeIdToken, it's necessary to set RedirectUri in several notification events.

In the AuthorizationCodeReceived notification, you can set the RedirectUri on TokenEndpointRequest to ensure the same value is also passed in the token request.

RedirectToIdentityProvider = n =>
{
    n.ProtocolMessage.RedirectUri = redirectUrl;
    // other settings   
}
AuthorizationCodeReceived = n =>
{
    n.TokenEndpointRequest.RedirectUri = redirectUrl;
    // other settings   
}
like image 184
Chris Avatar answered Sep 17 '22 19:09

Chris


I know this is an old post and the answer is already mentioned. But it still took me a while to figure out how to set the dynamic RedirectUri.

I was assigning RedirectUri in OpenIdConnectAuthenticationOptions and RedirectToIdentityProvider, which was causing issues.

We should assign RedirectUri only in RedirectToIdentityProvider event.

For someone who needs help, you can check my code here

like image 35
Harshal Avatar answered Sep 18 '22 19:09

Harshal