【发布时间】:2018-08-13 16:06:51
【问题描述】:
我正在开发一个使用 ADFS 身份验证的 ASP.NET MVC 应用程序,并且在我们的生产日志文件中出现以下错误,我正试图找出导致此问题的原因,因为我认为它正在阻止一些用户无法访问我们的应用程序。
错误如下:
System.IdentityModel.Tokens.SecurityTokenExpiredException: IDX10223: Lifetime validation failed. The token is expired.
ValidTo: '08/13/2018 12:59:35'
Current time: '08/13/2018 13:15:34'.
虽然我不能确定,但由于我没有错误发生时间的时间戳,我相信它导致了经典的 ASP.NET Server Error in '/' Application,这是我在日志中看到的唯一错误将与该页面出现相关。
在搜索 Stack Overflow 时,我看到对 JWT 授权的引用,这不是我们的应用程序使用的。或者至少我们没有使用任何明确使用 JWT 进行身份验证的东西,这可能是幕后发生的事情。我还看到一些帖子指出,如果身份验证服务器和应用程序服务器时间不同步,则可能会发生此错误;我正在与我的 IT 团队合作,以验证这些服务器的时钟是否同步并将相应更新。
我们的应用程序使用单一的 MVC 路由来为我们的 Angular 应用程序提供服务,并且只在该登录页面上强制执行身份验证;我们的 API 控制器对它们没有特定的授权要求(我知道,糟糕的安全实践,这是我试图与我团队的架构师进行的另一场对话)。
在等待有关时钟的信息时,是否有其他可能的选择可以调查?
OWIN 启动代码
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
// Workaround for this bug: http://katanaproject.codeplex.com/workitem/197
app.UseKentorOwinCookieSaver();
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
CookieSecure = CookieSecureOption.Always,
CookieName = "Adfs Cookie Name",
});
app.UseWsFederationAuthentication(new WsFederationAuthenticationOptions
{
MetadataAddress = WebConfigurationManager.AppSettings["WSFederation:MetadataAddress"],
Wtrealm = WebConfigurationManager.AppSettings["WSFederation:Realm"],
SignOutWreply = WebConfigurationManager.AppSettings["WSFederation:Realm"],
Notifications = new WsFederationAuthenticationNotifications
{
RedirectToIdentityProvider = ctx =>
{
if (IsAjaxRequest(ctx.Request))
{
ctx.HandleResponse();
}
return Task.FromResult(0);
}
}
});
return app;
}
private static bool IsAjaxRequest(IOwinRequest request)
{
var query = request.Query;
if (query != null && query["X-Requested-With"] == "XMLHttpRequest")
{
return true;
}
var headers = request.Headers;
if (headers != null && headers["X-Requested-With"] == "XMLHttpRequest")
{
return true;
}
return false;
}
}
【问题讨论】:
-
正确 - 没有 JWT。 WS-Fed 使用 SAML 令牌。
标签: asp.net asp.net-mvc owin adfs