ASP.NET Core 3 React SPA 模板 - 设置 AccessTokenLifetime
ASP.NET Core 3 React SPA Template - Set AccessTokenLifetime
我正在使用最新的 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
经过一番搜索后,我发现您可以在 Startup
中调用 AddApiAuthorization<ApplicationUser, ApplicationDbContext>();
期间执行此操作
替换为:
services.AddIdentityServer()
.AddApiAuthorization<ApplicationUser, ApplicationDbContext>(opt =>
{
foreach (var c in opt.Clients)
c.AccessTokenLifetime = 120; // Expiration in Seconds
});
所有 Token settings for Identity Server 似乎都可以在这里设置。
请注意,Clients
的收集是由您的配置决定的。在基本dotnet net react -o <name> -au Individual
模板的情况下,以下是在appSettings.json
中使用项目名称(dotnet
命令的-o
选项):
"IdentityServer": {
"Clients": {
"ReactAppIdentity": {
"Profile": "IdentityServerSPA"
}
}
我仔细研究了源代码,但不幸的是我找不到通过配置来设置这些设置的方法。
我正在使用最新的 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
经过一番搜索后,我发现您可以在 Startup
AddApiAuthorization<ApplicationUser, ApplicationDbContext>();
期间执行此操作
替换为:
services.AddIdentityServer()
.AddApiAuthorization<ApplicationUser, ApplicationDbContext>(opt =>
{
foreach (var c in opt.Clients)
c.AccessTokenLifetime = 120; // Expiration in Seconds
});
所有 Token settings for Identity Server 似乎都可以在这里设置。
请注意,Clients
的收集是由您的配置决定的。在基本dotnet net react -o <name> -au Individual
模板的情况下,以下是在appSettings.json
中使用项目名称(dotnet
命令的-o
选项):
"IdentityServer": {
"Clients": {
"ReactAppIdentity": {
"Profile": "IdentityServerSPA"
}
}
我仔细研究了源代码,但不幸的是我找不到通过配置来设置这些设置的方法。