【发布时间】:2015-08-06 16:02:45
【问题描述】:
我在同一个 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 错误 - 重定向后不允许使用方法(我会处理尾部斜杠)。
有关信息,我在 stackoverflow 上看到了这个问题: URL redirection from ADFS server
但它并没有真正回答我的问题,因为我不理解 Andrew Lavers 评论中的句子“(...) WIF 将处理 URL_1 处的响应,然后负责将用户重定向到 URL_2”。
如何将多个端点添加到一个 RP 信任? 或者如何将用户重定向到原始 URL? (考虑到所有应用程序都在同一个域中)。
提前感谢您的帮助。
【问题讨论】:
标签: c# authentication redirect owin adfs