【问题标题】:How to add multiple endpoints to adfs如何将多个端点添加到 adfs
【发布时间】: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


    【解决方案1】:

    您应该能够根据触发身份验证流程的应用程序设置 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);
                }
            }
        });
    
    【解决方案2】:

    这里的问题是,即使这样做,ADFS 服务器也不需要遵守给定的 Wreply 参数。默认情况下,ADFS 总是在成功登录后重定向到 Wtrealm。

    在我们的例子中,我们希望通过 ADFS 对 2 个测试服务器、1 个生产服务器进行身份验证,并为开发人员 (localhost) 启用登录。由于重定向问题,每个服务器都需要自己的信赖方信任。

    这里的理想解决方案是为每个运行应用程序的服务器以及https://localhost:44300(Visual Studio 默认 SSL 端口)单独创建 RP 信任,以便开发人员也可以进行身份​​验证。为了允许https://localhost:44300,首选选项可能存在一些安全问题,例如在 Azure VM 上设置开发 ADFS。

    【讨论】:

      猜你喜欢
      • 2023-03-22
      • 2019-03-22
      • 2021-05-04
      • 1970-01-01
      • 1970-01-01
      • 2020-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多