如何使用Sustainsys Saml2从Idp启动的登录中检索声明?

问题描述 投票:0回答:1

我正在尝试将对SAML身份验证的支持添加到具有ASP.NET Core身份(不是IdentityServer)的ASP.NET Core MVC应用程序中。使用StubIdp进行测试时,该流“起作用”-SAMLResponse被发布到/Saml2/Acs,并且我使用Identity.External cookie重定向到应用程序,但是我的ClaimsPrincipal为空且未经身份验证。即使我使用数据库中已经存在的用户的NameID,声明也完全是空的。

我还在控制台日志中看到以下内容:Sustainsys.Saml2.AspNetCore2.Saml2Handler: Information: Successfully processed SAML response Microsoft.IdentityModel.Tokens.Saml2.Saml2Id and authenticated JohnDoe

我安装了Sustainsys.Saml2.AspNetCore2程序包,并将服务配置添加到startup.cs如下:

services.AddAuthentication()
                .AddSaml2(async options =>
                {
                    var azureServiceTokenProvider = new AzureServiceTokenProvider();
                    var keyVaultClient = new KeyVaultClient(
                        new KeyVaultClient.AuthenticationCallback(
                            azureServiceTokenProvider.KeyVaultTokenCallback));

                    var certificateSecret = await keyVaultClient.GetSecretAsync($"https://{Configuration["KeyVaultName"]}.vault.azure.net/", Configuration["ServiceProviderCertName"]);
                    var privateKeyBytes = Convert.FromBase64String(certificateSecret.Value);

                    options.SPOptions.EntityId = new EntityId(Configuration["BaseUrl"] + "/Saml2");
                    options.SPOptions.ReturnUrl = new Uri(Configuration["BaseUrl"]);

                    IdentityProvider idp = new IdentityProvider(
                            new EntityId("https://stubidp.sustainsys.com/Metadata"), options.SPOptions)
                    {
                        LoadMetadata = true,
                        MetadataLocation = "https://stubidp.sustainsys.com/Metadata",
                        AllowUnsolicitedAuthnResponse = true
                    };

                    options.IdentityProviders.Add(idp);

                    options.SPOptions.ServiceCertificates.Add(new X509Certificate2(privateKeyBytes));
                });

Configuration["BaseUrl"]是我的应用程序的基本URL,在本例中为localhost端口。

我显然缺少了一些东西,但我不知道是什么。我是否需要以某种方式显式地将Saml2服务连接/映射到ASP.NET Core Identity?

asp.net-core asp.net-core-identity sustainsys-saml2
1个回答
0
投票

能够根据this GitHub issue中的注释解决此问题。

我的评论解释了我如何实现变通方法:https://github.com/Sustainsys/Saml2/issues/1030#issuecomment-616842796

© www.soinside.com 2019 - 2024. All rights reserved.