滑动续期与自动刷新:
Web:访问令牌 10 分钟;活跃时自动轮换刷新令牌;连续无操作 30 分钟后清除登录并跳转登录页。 App:会话窗口 3 天;打开 App、恢复前台或请求接口时自动刷新并重新顺延 3 天。 普通登录和 SSO 使用同一策略。 刷新令牌只以 SHA-256 摘要入库,每次刷新都会轮换,旧令牌无法再次使用;退出登录会吊销刷新令牌。 网络临时故障不会误清登录状态,多标签页同时刷新也做了竞争处理。
This commit is contained in:
@@ -122,7 +122,7 @@ public sealed class SsoControllerTests
|
||||
var cache = provider.GetRequiredService<IDistributedCache>();
|
||||
var controller = new SsoController(
|
||||
userManager,
|
||||
new StubTokenService(),
|
||||
new StubAuthSessionService(),
|
||||
cache,
|
||||
Options.Create(new SsoOptions
|
||||
{
|
||||
@@ -154,9 +154,27 @@ public sealed class SsoControllerTests
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class StubTokenService : ITokenService
|
||||
private sealed class StubAuthSessionService : IAuthSessionService
|
||||
{
|
||||
public string Create(ApplicationUser user, IEnumerable<string> roles) =>
|
||||
"test-token";
|
||||
public Task<AuthSessionResult> CreateAsync(
|
||||
ApplicationUser user,
|
||||
IEnumerable<string> roles,
|
||||
AuthenticationClientType clientType,
|
||||
CancellationToken cancellationToken = default) =>
|
||||
Task.FromResult(new AuthSessionResult(
|
||||
"test-token",
|
||||
DateTime.UtcNow.AddMinutes(10),
|
||||
"test-refresh-token-value-with-sufficient-length",
|
||||
DateTime.UtcNow.AddMinutes(30),
|
||||
user,
|
||||
roles.ToList()));
|
||||
|
||||
public Task<AuthSessionResult?> RefreshAsync(
|
||||
string refreshToken,
|
||||
CancellationToken cancellationToken = default) => Task.FromResult<AuthSessionResult?>(null);
|
||||
|
||||
public Task RevokeAsync(
|
||||
string refreshToken,
|
||||
CancellationToken cancellationToken = default) => Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user