我有一个ASP NET Core 3.0
应用程序,正在使用Azure Active Directory
进行身份验证。硒以下的强化配置
services.AddAuthentication(options =>
{
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
})
.AddOpenIdConnect(options =>
{
options.Authority = auth.Authority;
options.ResponseType = OpenIdConnectResponseType.IdToken;
options.SignedOutRedirectUri = auth.SignedOutRedirectUri;
options.CallbackPath = auth.CallbackPath;
options.ClientId = auth.ClientId;
})
.AddCookie(options =>
{
options.AccessDeniedPath = "/Home/AccessDenied/";
options.ExpireTimeSpan = TimeSpan.FromMinutes(20);
});
cookie
在闲置20分钟后更改页面时会自动重新生成,但是如果我调用API Controller
,则不会发生这种情况。当我进行AJAX
呼叫且令牌已过期时,我该怎么做以自动刷新令牌?我是否忘记在配置中添加某些内容?
此earlier post可能会给您一些想法-来自遵循相同概念的以前的MS技术堆栈。
您可能对SlidingExpiration选项感到幸运。传统上,由于2种不同的Authorize属性,这一直是个问题区域。
WIDER POINT
导致代码更简单的更简洁的体系结构是避免在同一服务器端组件中混合Web和API代码。
当然,这可能不在当前项目的范围内,但是对于下一个项目,您可能会考虑:
[如果有兴趣,请查看我的Azure AD示例: