我在 .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/