【发布时间】: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