【发布时间】:2018-08-16 14:23:52
【问题描述】:
我有一个 ASP.NET 站点,它使用 Open Id Connect 向 Identity Server 进行身份验证。 当身份验证令牌即将到期时,我添加了一个静默身份验证(提示=无),它将更新令牌而不向用户显示任何登录对话框。 只要用户仍然登录到 Identity Server,这就可以正常工作。
如果用户不再登录,则返回“login_required”错误。我想通过让它静默失败并将用户重定向回身份验证开始的页面来处理此错误。 当向 AuthenticationFailed 通知返回错误时,RedirectUri 似乎不可用。报错后有什么办法可以访问RedirectUri?
我的配置看起来像这样(缩写):
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions {
...
Notifications = new OpenIdConnectAuthenticationNotifications
{
AuthenticationFailed = context =>
{
// if we failed to authenticate without prompt
if (context.ProtocolMessage.Error == "login_required")
{
context.HandleResponse();
//context.Response.Redirect("The url to the page where RedirectToIdentityProvider was triggered");
return Task.FromResult(0);
}
context.HandleResponse();
context.Response.Write(context.Exception.Message);
return Task.FromResult(0);
},
RedirectToIdentityProvider = async context =>
{
...
if (ShouldReAuthenticate())
{
context.ProtocolMessage.SetParameter("prompt", "none");
}
...
}
}
});
【问题讨论】:
标签: asp.net-mvc identityserver4 openid-connect