简体   繁体   English

使用 ITfoxtec.Identity.Saml2 登录用户

[英]Use ITfoxtec.Identity.Saml2 to login user

I am trying to implement SAML2.0 authentication using IdentityServer4 and ITfoxtec.Identity.Saml2 library.我正在尝试使用 IdentityServer4 和 ITfoxtec.Identity.Saml2 库实现 SAML2.0 身份验证。

The first step is to login via the LDAP connection and this part worked well and i get user claims.第一步是通过 LDAP 连接登录,这部分运行良好,我收到了用户声明。

Next step is to integrate login using AD FS下一步是使用 AD FS 集成登录

I followed principally this tutorial我主要遵循本教程

https://developer.okta.com/blog/2020/10/23/how-to-authenticate-with-saml-in-aspnet-core-and-csharp https://developer.okta.com/blog/2020/10/23/how-to-authenticate-with-saml-in-aspnet-core-and-csharp

The Saml configuration code is below Saml 配置代码如下

services.Configure<Saml2Configuration>(saml2Configuration =>
{
    saml2Configuration.AllowedAudienceUris.Add(saml2Configuration.Issuer);

    var entityDescriptor = new EntityDescriptor();
    entityDescriptor.ReadIdPSsoDescriptorFromUrl(new Uri(Configuration["Saml2:IdPMetadata"]));
    if (entityDescriptor.IdPSsoDescriptor != null)
    {
        saml2Configuration.SingleSignOnDestination = entityDescriptor.IdPSsoDescriptor.SingleSignOnServices.First().Location;
        saml2Configuration.SignatureValidationCertificates.AddRange(entityDescriptor.IdPSsoDescriptor.SigningCertificates);
    }
    else
    {
        throw new Exception("IdPSsoDescriptor not loaded from metadata.");
    }
});

services.AddSaml2();

After server redirection and before displaying the Idp login page i have an error "certificate are not properly configured at application end"在服务器重定向之后和显示 Idp 登录页面之前,我有一个错误“证书在应用程序端没有正确配置”

This is the first time that I deal with SAML protocol.这是我第一次处理 SAML 协议。 Any help is appreciated.任何帮助表示赞赏。

Edit: The error is on the AD FS Side编辑:错误在 AD FS 端

For more information, the ITfoxtec.Identity.Saml2 documentation and a ASP.NET Core sample .有关详细信息,请参阅 ITfoxtec.Identity.Saml2文档ASP.NET 核心示例

I'm in doubt where you see the error.我怀疑你在哪里看到错误。 Is it at the IdentityServer4 application or in AD FS?它是在 IdentityServer4 应用程序中还是在 AD FS 中?

The configuration you show read the AD FS metadata and set up the IdP configuration.您显示的配置读取 AD FS 元数据并设置 IdP 配置。 You also need to load the relying party configuration.您还需要加载依赖方配置。

services.Configure<Saml2Configuration>(Configuration.GetSection("Saml2"));

and set the relying party signing certificate eg, like this并设置依赖方签名证书,例如,像这样

saml2Configuration.SigningCertificate = CertificateUtil.Load(AppEnvironment.MapToPhysicalFilePath(
            Configuration["Saml2:SigningCertificateFile"]), 

The configuration together一起配置

services.Configure<Saml2Configuration>(Configuration.GetSection("Saml2"));
services.Configure<Saml2Configuration>(saml2Configuration =>
{
    saml2Configuration.SigningCertificate = CertificateUtil.Load(AppEnvironment.MapToPhysicalFilePath(
        Configuration["Saml2:SigningCertificateFile"]), Configuration["Saml2:SigningCertificatePassword"]);
    saml2Configuration.AllowedAudienceUris.Add(saml2Configuration.Issuer);

var entityDescriptor = new EntityDescriptor();
    entityDescriptor.ReadIdPSsoDescriptorFromUrl(new Uri(Configuration["Saml2:IdPMetadata"]));
if (entityDescriptor.IdPSsoDescriptor != null)
    {
        saml2Configuration.SingleSignOnDestination = entityDescriptor.IdPSsoDescriptor.SingleSignOnServices.First().Location;
        saml2Configuration.SingleLogoutDestination = entityDescriptor.IdPSsoDescriptor.SingleLogoutServices.First().Location;
        saml2Configuration.SignatureValidationCertificates.AddRange(entityDescriptor.IdPSsoDescriptor.SigningCertificates);
    }
else
    {
        throw new Exception("IdPSsoDescriptor not loaded from metadata.");
    }
});
services.AddSaml2();  

Remark评论

To solve a situation like yours I have created FoxIDs which support OpenID Connect and can be connected to an AD FS with SAML 2.0.为了解决像您这样的情况,我创建了支持 OpenID Connect 并且可以使用 SAML 2.0 连接到 AD FS 的FoxID FoxIDs handles the conversion between OpenID Connect and SAML 2.0. FoxIDs 处理 OpenID Connect 和 SAML 2.0 之间的转换。 Actually, FoxIDs also use the ITfoxtec.Identity.Saml2 library.实际上,FoxID 也使用 ITfoxtec.Identity.Saml2 库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ITfoxtec.Identity.Saml2 无效 URI 问题 - ITfoxtec.Identity.Saml2 Invalid URI Issue Map SAML 声明使用 ITfoxtec.Identity.Saml2 - Map SAML claims using ITfoxtec.Identity.Saml2 User.Identity.IsAuthenticated 在使用 ITFoxtec 的 SAML 2.0 中始终为假 - User.Identity.IsAuthenticated Always false in SAML 2.0 using ITFoxtec ValidateRelyingParty方法从itfoxtec-identity-saml2的哪里派生? - Where does the method ValidateRelyingParty derive from in itfoxtec-identity-saml2? ITfoxtec.Identity.Saml2.Saml2RequestException:“不完全是一个断言元素。” - ITfoxtec.Identity.Saml2.Saml2RequestException: 'There is not exactly one Assertion element.' 使用 ITfoxtec 将经过身份验证的用户从具有 SAML SSO 的外部 SP 登录到托管 SP - Sign in an Authenticated User from External SP with SAML SSO using ITfoxtec to the managed SP ITFOXTEC SAML2 CORE 示例无法编译 - ITFOXTEC SAML2 CORE example will not compile 使用formsauthentication进行登录并使用HttpContext.Current.User.Identity - Using formsauthentication for login and use HttpContext.Current.User.Identity 从 SAML 身份提供者成功登录后,AuthenticationResponseGrant 为空? - AuthenticationResponseGrant is null after successful login from SAML Identity Provider? 使用QueueBackgroundWorkItem和用户身份? - Use QueueBackgroundWorkItem with User Identity?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM