情景:
Microsoft.Owin.Security.WsFederation
我的问题:
这是我的Startup.Configuration方法中的代码:
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseWsFederationAuthentication(
new WsFederationAuthenticationOptions
{
MetadataAddress = "https://.../FederationMetadata.xml",
Wtrealm = "...",
}
);
答案 0 :(得分:3)
您有两种方法可以实现您的目标:
1.一种是在AD FS配置它。我个人认为这是正确的方法,因为AD FS是IdP,它应该是控制其用户是否可以访问该应用程序的人。在这种情况下,公司应该或不应该允许某人使用它的一些资源(当然有反论据)。这可以通过AD FS管理GUI在域控制器上轻松完成。以下答案大致描述了这一点: https://serverfault.com/a/676930/321380
2.其次是以这种方式在OWIN WSFed中间件上使用Notifications对象:
Notifications = new WsFederationAuthenticationNotifications()
{
SecurityTokenValidated = (context) =>
{
//extract claims' values and check identity data against your own authorization logic
bool isAuthorized = CheckForUnauthorizedAccess();
if (!isAuthorized)
{
throw new SecurityTokenValidationException("Unauthorized access attemp by {some_identifier}");
}
return Task.FromResult(0);
},
AuthenticationFailed = (context) =>
{
if (context.Exception is an unauthorized exception)
{
context.OwinContext.Response.Redirect("<unauthorized_redirect_url>");
}
context.HandleResponse(); // Suppress the exception
//exception logging goes here
return Task.FromResult(0);
}
}