Sustainsys Saml2 Handler AuthenticateAsync() 方法操作未实现

Art*_*ros 5 adfs saml-2.0 asp.net-core sustainsys-saml2

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

NotImplementedException: The method or operation is not implemented.
Sustainsys.Saml2.AspNetCore2.Saml2Handler.AuthenticateAsync()
Run Code Online (Sandbox Code Playgroud)

这是我的实现,我的应用程序在 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();

Run Code Online (Sandbox Code Playgroud)

在我的控制器上 尝试类似于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);
        }
}


Run Code Online (Sandbox Code Playgroud)

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

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

And*_*bel 2

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

我猜这个LoginAdfs()方法工作得很好,但它LoginCallback失败了。原因应该是调用HttpContext.AuthenticationAsync(Saml2Defaults.Scheme).

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