【问题标题】:Sustainsys Saml2 Handler AuthenticateAsync() method operation is not implementedSustainsys Saml2 Handler AuthenticateAsync() 方法操作未实现
【发布时间】:2019-10-29 13:22:56
【问题描述】:

我正在我的 Saml2 的 Asp net Core 应用程序中尝试一个简单的实现,以与 Ad FS 服务器集成。我不知道为什么我会收到这个错误。我从 gitHub 下载了示例并尝试在我的应用程序中进行调整。

NotImplementedException: The method or operation is not implemented.
Sustainsys.Saml2.AspNetCore2.Saml2Handler.AuthenticateAsync()

这是我的实现,我的应用程序在 Asp Net Core 上运行

启动时

                services
                    .AddAuthentication(sharedOptions =>
                    {
                        sharedOptions.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                        sharedOptions.DefaultChallengeScheme = Saml2Defaults.Scheme;
                    })
                    .AddSaml2(options =>
                    {
                        options.SPOptions.EntityId = new EntityId("http://myAdfsServer.myDomain.com/adfs/services/trust");
                        options.SPOptions.ReturnUrl = new Uri("https://localhost:5000");
                        options.IdentityProviders.Add(
                            new IdentityProvider(new EntityId("http://myAdfsServer.myDomain.com/adfs/services/trust"), options.SPOptions)
                            {
                               LoadMetadata = true,
                               MetadataLocation = "https://myAdfsServer.myDomain.com/FederationMetadata/2007-06/FederationMetadata.xml"
                                //MetadataLocation = "FederationMetadata.xml"
                            });

                        //options.SPOptions.ServiceCertificates.Add(new X509Certificate2(certificate.ToString()));
                    })
                    .AddCookie();

在我的控制器上 尝试类似于Sustainsys SAML2 Sample for ASP.NET Core WebAPI without Identity


    [Authorize(AuthenticationSchemes = Saml2Defaults.Scheme)]
    public class AuthenticationController : Controller
    {
        public AuthenticationController()
        {

        }

        [AllowAnonymous]
        public async Task LoginAdfs()
        {
            string redirectUri = string.Concat("https://localhost:5000", "/verifyAdfs");
            try
            {
                new ChallengeResult(
                    Saml2Defaults.Scheme,
                    new AuthenticationProperties
                    {
                        RedirectUri = Url.Action(nameof(LoginCallback), new { redirectUri })
                    });
            }catch(Exception e)
            {

            }
        }

        [AllowAnonymous]
        public async Task<IActionResult> LoginCallback(string returnUrl)
        {
            var authenticateResult = await HttpContext.AuthenticateAsync(Saml2Defaults.Scheme);

            //_log.Information("Authenticate result: {@authenticateResult}", authenticateResult);

            // I get false here and no information on claims etc.
            if (!authenticateResult.Succeeded)
            {
                return Unauthorized();
            }

            var claimsIdentity = new ClaimsIdentity("Email");
            claimsIdentity.AddClaim(authenticateResult.Principal.FindFirst(ClaimTypes.NameIdentifier));

           // _log.Information("Logged in user with following claims: {@Claims}", authenticateResult.Principal.Claims);

            await HttpContext.SignInAsync("Email", new ClaimsPrincipal(claimsIdentity));

            return LocalRedirect(returnUrl);
        }
}


注意:我有一个客户端不会在 URL 中公开他的元数据,所以我需要对其进行调整并手动设置元数据参数

我遇到了这个错误,我什至没有点击我的方法 LoginAdfs。

【问题讨论】:

  • 您已经找到解决方案了吗?我也有同样的问题...

标签: asp.net-core saml-2.0 adfs sustainsys-saml2


【解决方案1】:

Saml2 处理程序不能用作身份验证方案,它是一个挑战方案

我猜LoginAdfs() 方法工作正常,但失败的是LoginCallback。原因应该是对HttpContext.AuthenticationAsync(Saml2Defaults.Scheme)的调用。

您应该使用 cookie 方案进行身份验证 - 因为这是保持会话的原因。在内部完成挑战后,Saml2 处理程序将使用DefaultSignInScheme 将结果保存在会话中(通过 cookie,因为这是默认登录方案)。

【讨论】:

  • 我很难让它工作。以前我实现了 WS-Protocol,它有点简单。我不必使用这个“LoginCallBack”方法。它甚至没有命中 Ad FS 服务器。知道有什么问题吗?此外,GitHub 中提供的示例对我没有帮助。除了启动配置之外,我可能还缺少另一个实现吗?
  • 你能用一些示例代码解释一下吗?我不明白如何使用 cookie 方案进行身份验证......似乎 Saml2Handler 创建了一个自定义 cookie“Saml2.RelayState”。
  • @PietervanderHeijden 你明白了吗?我正在努力实现同样的目标。
  • @Justin 不,我无法让它工作......因此,我切换到了 ComponentSpace。这个解决方案效果很好,并且有(很多)例子。
  • @PietervanderHeijden 感谢您的提示,我从 SustainSys 切换到 ComponentSpace,它现在运行良好。我在 SustainSys 上花了一周时间,但从未在挑战回调中设置外部 cookie,而连接 ComponentSpace 需要 4 个小时。不幸的是,它不使用 ASP.NET Core / Identity Server 身份验证方案外部 cookie 方法,因此与我们的 OIDC 和 OAuth2 SSO 流程不一致。相反,它只是在内部处理请求表单的 SAMLResponse 的验证和解析。哦,好吧,它有效,继续……
猜你喜欢
  • 1970-01-01
  • 2016-04-06
  • 2019-03-15
  • 1970-01-01
  • 2022-07-18
  • 2020-07-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多