asp.net-mvc - 如何在 .NET Core 3.1 中使用 Azure AD Saml2 身份验证进行 SSO

标签 asp.net-mvc azure .net-core saml-2.0 sustainsys-saml2

我在 .NET Core 3.1 中使用 Sustainsys.Saml2 进行 Azure AD Saml2 身份验证。我可以进行身份​​验证,但在登录页面自动重定向到此地址 https://localhost:44378/Saml2/Acs.system 后添加“/Saml2/Acs”。我找不到使用它的正确教程。我需要正确使用回复 URL。一旦成功通过身份验证,我需要调用特定的 Controller 。

// Startup.cs class

services.AddAuthentication(sharedOptions =>
            {
                sharedOptions.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                sharedOptions.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
               sharedOptions.DefaultChallengeScheme = "Saml2";
            })
            .AddSaml2(options =>
            {
               options.SPOptions.EntityId = new EntityId("https://localhost:44378/Saml2");
                options.IdentityProviders.Add(
                new IdentityProvider(
                  new EntityId("https://sts.windows.net/9e5692e4-bd0a-414d-8b61-98f59dab156e/"), options.SPOptions)
                {
                    MetadataLocation = "https://login.microsoftonline.com/7e5692e4-bgf0a-4148-8b61-98f59dab156e/federationmetadata/2007-06/federationmetadata.xml?appid=1729db2f-0156-41cb-b4e3-d54bed555b85"
                });
            })
            .AddCookie();

            services.AddMvc(options =>
            {
                var policy = new AuthorizationPolicyBuilder()
                    .RequireAuthenticatedUser()
                    .Build();
                options.Filters.Add(new AuthorizeFilter(policy));
            });

错误消息是

找不到此本地主机页面未找到以下网址的网页:https://localhost:44378/Saml2/Acs HTTP 错误 404

最佳答案

您需要添加app.UseAuthentication();在 Startup 类中的配置方法下。

public class Startup
{
    public void Configure(IApplicationBuilder app)
    {
        app.UseAuthentication();
    }
}

这将在您的应用程序中启用 SAML2 中间件。

关于asp.net-mvc - 如何在 .NET Core 3.1 中使用 Azure AD Saml2 身份验证进行 SSO,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64002282/

相关文章:

.net-core - Orleans - 如何提高提醒的准确性

c# - 无法从程序集“Microsoft.Azure.WebJobs.Host”加载类型 'Microsoft.Azure.WebJobs.Host.Scale.ConcurrencyManager'

c# - 在 asp.net Web api 应用程序中自定义 System.Web.Http.AuthorizeAttribute

asp.net - 将STS和依赖方合并到同一个网站中

asp.net-mvc - 如何在 ASP.NET MVC 中使用带有 PostBack 的服务器控件?

azure - Azure 数据工厂的 SFTP 支持

.net - 如何在 ASP.NET 中找到无法序列化的对象?

azure - 创建 Azure 任务自动化时出现未授权错误

azure - 我可以更改应用服务计划/应用服务以使用应用服务环境吗

c# - 基于 System.IO.Pipelines 长度字段的 TCP 解码