如何向adfs添加多个端点
本文关键字:端点 添加 adfs | 更新日期: 2023-09-27 18:06:46
我在同一个web服务器(II7)上有很多web应用程序:比如mydomain/app1, mydomain/app2,…等等......我试图通过OWIN添加ADFS认证。以下是我所做的:
[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的用户也是如此。
但是我希望在ADFS中只添加一个依赖方信任(因为有很多应用程序并且都使用相同的索赔规则)。
我已经尝试了不同的配置,但我不能做我想要的:
如果RP端点是mydomain/app1/,身份验证是可以的,但是所有请求(甚至来自mydomain/app2的请求都被重定向到app1),显然
如果RP端点只是mydomain/,我得到一个405.0 http错误-重定向后不允许的方法(我照顾尾随斜杠)。
但这并不能真正解决我的问题,因为我不理解句子"……"WIF将处理URL_1的响应,然后负责将用户重定向到URL_2"(Andrew Lavers的评论)。
如何将多个端点添加到一个RP信任中?或者如何将用户重定向到原始URL ?(考虑到所有应用程序都在同一域中)。
提前感谢您的帮助。
您应该能够根据触发身份验证流的应用程序设置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);
}
}
});
这里的问题是,即使这样做,ADFS服务器也不需要遵守给定的Wreply参数。默认情况下,ADFS总是在成功登录后重定向到Wtrealm。
在我们的案例中,我们希望通过ADFS与2个测试服务器,1个生产服务器进行身份验证,并为开发人员(本地主机)启用登录。由于重定向问题,每个服务器都需要自己的依赖方信任。
理想的解决方案是分别为运行应用程序的每个服务器和https://localhost:44300 (Visual Studio默认SSL端口)创建RP信任,以便开发人员也可以进行身份验证。对于允许https://localhost:44300,可能会有一些安全问题,首选的选择是设置开发ADFS,例如在Azure VM上。