[英]How to use Azure AD Saml2 authentication for SSO in .NET Core 3.1
我在 .NET Core 3.1 中使用 Sustainsys.Saml2 进行 Azure AD Saml2 身份验证。我可以进行身份验证,但在登录页面重定向到此地址后 https://localhost:44378/Saml2/Acs.system 自动添加“/ Saml2/Acs”。我找不到使用它的正确教程。 我需要正确使用回复 URL。 一旦成功通过身份验证,我需要调用特定的控制器。
// 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 ERROR 404
您需要添加 app.UseAuthentication(); 在 Startup 类中的 Configure 方法下。
public class Startup
{
public void Configure(IApplicationBuilder app)
{
app.UseAuthentication();
}
}
这将在您的应用程序中启用 SAML2 中间件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.