ASP.NET Core 3 React SPA 模板 - 设置 AccessTokenLifetime

And*_*ffy 5 identityserver4 spa-template asp.net-core-3.0

我正在使用最新的 react SPA .NET Core 3 模板,想知道有没有办法为客户端设置“AccessTokenLifetime”,显然该客户端是我的 SPA。

我一直在看这里https://github.com/aspnet/AspNetCore.Docs/blob/master/aspnetcore/security/authentication/identity-api-authorization.md#application-profiles我尝试了很多不同的事物。

但似乎没有设置客户端属性的方法,除了上面页面上详细介绍的几个,例如 RedirectUri、LogoutUri

Off*_*oes 6

有点狩猎后,我发现,你可以在调用过程中做AddApiAuthorization<ApplicationUser, ApplicationDbContext>();Startup

替换为:

services.AddIdentityServer()
    .AddApiAuthorization<ApplicationUser, ApplicationDbContext>(opt =>
    {
        foreach (var c in opt.Clients)
            c.AccessTokenLifetime = 120; // Expiration in Seconds
    });
Run Code Online (Sandbox Code Playgroud)

Identity Server 的所有令牌设置似乎都可以在这里设置。

请注意,集合Clients是由您的配置决定的。在基本dotnet net react -o <name> -au Individual模板的情况下,以下是在appSettings.json使用项目的名称(命令的-o选项dotnet):

"IdentityServer": {
    "Clients": {
        "ReactAppIdentity": {
            "Profile": "IdentityServerSPA"
    }
}
Run Code Online (Sandbox Code Playgroud)

我仔细研究了源代码,但不幸的是我看不到通过配置来设置这些设置的方法。