Search code examples
owinmiddlewareopenid-connect

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 .


Solution

  • This can be done via Notification event RedirectToIdentityProvider . Something like this:

     Notifications = new OpenIdConnectAuthenticationNotifications
                     {
                         RedirectToIdentityProvider = async n =>
                         {
                             n.ProtocolMessage.RedirectUri = n.OwinContext.Request.Uri.Host;
                             n.ProtocolMessage.PostLogoutRedirectUri = n.OwinContext.Request.Uri.Host;
                         },
                         //other notification events...
                     }
    

    `