C# 如何向ADF添加多个端点
我在同一个web服务器(II7)上有很多web应用程序: 让我们假设mydomain/app1、mydomain/app2。。。等等 我正在尝试通过OWIN添加ADFS身份验证。 以下是我所做的:C# 如何向ADF添加多个端点,c#,authentication,redirect,owin,adfs,C#,Authentication,Redirect,Owin,Adfs,我在同一个web服务器(II7)上有很多web应用程序: 让我们假设mydomain/app1、mydomain/app2。。。等等 我正在尝试通过OWIN添加ADFS身份验证。 以下是我所做的: [assembly: OwinStartup(typeof(MyNamespace.Startup))] namespace MyNamespace { public class Startup { private static string realm = ConfigurationMana
[assembly: OwinStartup(typeof(MyNamespace.Startup))]
namespace MyNamespace
{
public class Startup
{
private static string realm = ConfigurationManager.AppSettings["ida:Wtrealm"];
private static string adfsMetadata = ConfigurationManager.AppSettings["ida:ADFSMetadata"];
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app);
app.Use((context, next) =>
{
SignIn(context);
return next.Invoke();
});
app.UseStageMarker(PipelineStage.Authenticate);
}
public void ConfigureAuth(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseWsFederationAuthentication(
new WsFederationAuthenticationOptions
{
Wtrealm = realm,
MetadataAddress = adfsMetadata
});
}
public void SignIn(IOwinContext context)
{
if (context.Authentication.User == null)
{
context.Authentication.Challenge(
WsFederationAuthenticationDefaults.AuthenticationType);
}
}
}
}
当用户访问mydomain/app1时,我希望他通过ADFS进行身份验证,然后重定向到mydomain/app1。对于访问mydomain/app2的用户来说也是如此
但我只希望在ADF中添加一个依赖方信任(因为有很多应用程序,并且都使用相同的声明规则)
我尝试了不同的配置,但我无法执行我想要的操作:
- 如果RP端点是mydomain/app1/,则身份验证是可以的,但显然所有请求(甚至来自mydomain/app2的请求)都会重定向到app1
- 如果RP端点仅为mydomain/,则在重定向后会得到一个405.0 http错误-不允许使用的方法(我会处理尾部斜杠)
提前感谢您的帮助。您应该能够根据触发身份验证流的应用程序设置wreply参数。大概是这样的:
app.UseWsFederationAuthentication(
new WsFederationAuthenticationOptions
{
Wtrealm = realm,
MetadataAddress = adfsMetadata,
Notifications = new WsFederationAuthenticationNotifications
{
RedirectToIdentityProvider = context =>
{
context.ProtocolMessage.Wreply = <construct reply URL from context.Request>;
return Task.FromResult(0);
}
}
});
app.UseWsFederationAuthentication(
新WsFederationAuthenticationOptions
{
Wtrealm=realm,
MetadataAddress=adfsMetadata,
通知=新WsFederationAuthenticationNotifications
{
RedirectToIdentityProvider=上下文=>
{
context.ProtocolMessage.Wreply=;
返回Task.FromResult(0);
}
}
});
这里的问题是,即使这样做,ADFS服务器也不需要遵守给定的Wreply参数。默认情况下,ADF总是在成功登录后重新定向到Wtrealm
在本例中,我们希望通过ADFS对2台测试服务器、1台生产服务器进行身份验证,并为开发人员(localhost)启用登录。由于重定向问题,每个服务器都需要自己的依赖方信任
这里的理想解决方案是为运行应用程序的每个服务器以及(VisualStudio默认SSL端口)分别创建RP信任,以便开发人员也可以进行身份验证。如果允许,可能会有一些安全问题,首选选项是在Azure VM上设置开发ADF