【问题标题】:Using Kentor + Windows Authentication on IdentityServer3在 IdentityServer3 上使用 Kentor + Windows 身份验证
【发布时间】:2017-06-02 07:57:12
【问题描述】:

我有一个使用 Windows Authentication Service 的 IdentityServer3。现在我想在我的 IdentityServer3 上处理 SAML2 协议,我看到 Kentor 可以为我做这件事。

问题是 Kentor 在所有示例中都使用 OpenID Connect,我搜索了一段时间,但找不到任何有关如何将 Kentor 与 WindowsAuth 结合使用的文档。经过多次尝试都没有成功,我来这里询问是否真的可以以及如何?

这是我在 Startup.cs 中的(非工作)配置:

public void Configuration(IAppBuilder appBuilder)
{
    appBuilder.Map("/windows", ConfigureWindowsTokenProvider);
    appBuilder.UseIdentityServer(GetIdentityServerOptions());
}

private void ConfigureWsFederation(IAppBuilder pluginApp, IdentityServerOptions options)
{
    var factory = new WsFederationServiceFactory(options.Factory);

    factory.Register(new Registration<IEnumerable<RelyingParty>>(RelyingParties.Get()));
    factory.RelyingPartyService = new Registration<IRelyingPartyService>(typeof(InMemoryRelyingPartyService));
    factory.CustomClaimsService = new Registration<ICustomWsFederationClaimsService>(typeof(ClaimsService));
    factory.CustomRequestValidator = new Registration<ICustomWsFederationRequestValidator>(typeof(RequestValidator));

    var wsFedOptions = new WsFederationPluginOptions
    {
        IdentityServerOptions = options,
        Factory = factory,
    };

    pluginApp.UseWsFederationPlugin(wsFedOptions);
}

private IdentityServerOptions GetIdentityServerOptions()
{
    DefaultViewServiceOptions viewServiceOptions = new DefaultViewServiceOptions();
    viewServiceOptions.CustomViewDirectory = HttpContext.Current.Server.MapPath("~/Templates");
    viewServiceOptions.Stylesheets.Add("/Content/Custom.css");

    IdentityServerServiceFactory factory = new IdentityServerServiceFactory()
        .UseInMemoryClients(new List<Client>())
        .UseInMemoryScopes(new List<Scope>());

    factory.ConfigureDefaultViewService(viewServiceOptions);
    factory.UserService = new Registration<IUserService>(resolver => new UserService());

    return new IdentityServerOptions
    {
        SigningCertificate = Certificate.Load(),
        Factory = factory,
        PluginConfiguration = ConfigureWsFederation,
        EventsOptions = new EventsOptions
        {
            RaiseSuccessEvents = true,
            RaiseFailureEvents = true,
        },
        AuthenticationOptions = new IdentityServer3.Core.Configuration.AuthenticationOptions
        {
            IdentityProviders = ConfigureIdentityProviders,
            EnableLocalLogin = false,
        },
        RequireSsl = true,
    };
}

private void ConfigureIdentityProviders(IAppBuilder app, string signInAsType)
{
    ConfigureWSFederationProvider(app, signInAsType);
    ConfigureKentorProvider(app, signInAsType);
}

private void ConfigureKentorProvider(IAppBuilder app, string signInAsType)
{
    SPOptions spOptions = new SPOptions
    {
        EntityId = new EntityId("Dropbox"),
    };
    KentorAuthServicesAuthenticationOptions kentorOptions = new KentorAuthServicesAuthenticationOptions(false)
    {
        Caption = "Windows",
        SignInAsAuthenticationType = signInAsType,
        SPOptions = spOptions,
    };
    IdentityProvider idp = new IdentityProvider(new EntityId("http://stubidp.kentor.se/Metadata"), spOptions)
    {
        Binding = Saml2BindingType.HttpRedirect,
        AllowUnsolicitedAuthnResponse = true,
        LoadMetadata = true,
    };
    kentorOptions.IdentityProviders.Add(idp);
    app.UseKentorAuthServicesAuthentication(kentorOptions);
}

private void ConfigureWSFederationProvider(IAppBuilder app, string signInAsType)
{
    app.UseWsFederationAuthentication(new WsFederationAuthenticationOptions()
    {
        AuthenticationType = "windows",
        Caption = "Windows",
        SignInAsAuthenticationType = signInAsType,

        MetadataAddress = serverHost + "windows",
        Wtrealm = "urn:idsrv3",
    });
}

private void ConfigureWindowsTokenProvider(IAppBuilder app)
{
    app.UseWindowsAuthenticationService(new WindowsAuthenticationOptions
    {
        IdpReplyUrl = serverHost,
        SigningCertificate = Certificate.Load(),
        EnableOAuth2Endpoint = false,
    });
}

此配置已构建,但当我使用 Dropbox SSO(使用 SAML2)时,我收到异常 No Idp with entity id "Dropbox" found

【问题讨论】:

  • Caption = "Windows", 在您的 Kentor 代码中看起来有问题,但听起来您的主要问题在其他地方。
  • 是的,可以在 IdentityServer3 中同时使用 Kentor.AuthServices 和 Windows 作为独立的外部身份提供者。我没有时间将我当前的代码提炼成一个较小的示例,但我从 github.com/KentorIT/authservices/tree/master/… 开始,然后从 IdentityServer3 中添加到 Windows auth 示例中
  • 感谢您的评论,但我需要让它们一起工作,而不是分开工作。这就是我这篇文章的重点。
  • 对不起,“分离”可能是错误的词。我的意思是在同一个登录页面上有“使用 Windows 登录”和“使用 XYZ SAML 登录”按钮的设置。这也是你的目标吗?或者你说让他们一起工作是什么意思?
  • 我的最终目标是通过 Windows 身份验证从 Dropbox(和其他使用 SAML2 的 SP)中对用户进行身份验证,我认为 Kentor 可以做到。

标签: c# windows-authentication saml-2.0 identityserver3 kentor-authservices


【解决方案1】:

您已将“Dropbox”配置为您的应用程序(SpOptions 中的那个)的身份(SAML2 术语中的EntityId)。那应该是一个标识您的应用程序的 URI。惯例是使用元数据的 URL (~/AuthServices)。

您需要使用保管箱 idp 的设置添加 IdentityProvider。另请注意,“Dropbox”的 EntityId 不起作用,因为 SAML2 标准要求 Entity ID 是绝对 URI。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-14
    • 2016-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多