动态设置RedirectUri

动态设置RedirectUri

本文介绍了OWIN OpenIdConnect中间件-动态设置RedirectUri的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以基于请求范围而不是应用程序范围为OpenIdConnectMessage设置RedirectUri属性吗?

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

我的应用程序服务于多个域(myapp.com,myapp.fr,..),并且基于域,它确定内容的默认语言.我需要在通过IdP登录后将用户重新带回同一个域,因此我需要找到一种方法,如何通过在startup.cs中配置中间件选项来为每个请求范围而不是应用程序范围设置RedirectUri.

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 .

推荐答案

这可以通过Notification事件RedirectToIdentityProvider完成.像这样:

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...
                 }

`

这篇关于OWIN OpenIdConnect中间件-动态设置RedirectUri的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 10:44