reactjs - 如何刷新访问令牌?(react app + asp.net 身份服务器)
问题描述
更改服务器上的用户数据时,我需要更改客户端上的令牌。例如,更改服务器上的一些数据后,我重新登录。我看到了这些更改,但是 Web 应用程序不会自动更新这些数据,也就是说,要使用它们,我需要退出应用程序并重新登录以接收新令牌。IdentityServer 4 的文档说令牌更新选项不适用于隐式流。但是可能有一些方法可以更新令牌(是否可以通过设置超时或其他方式来做到这一点)?
客户端的 IdentityServer4 设置:
// React AOO Client
new Client
{
ClientId = "airvector",
ClientName = "Airvector Ordering Online",
//AccessTokenType = AccessTokenType.Reference,
//AccessTokenLifetime = 30,
//IdentityTokenLifetime = 10,
AllowedGrantTypes = GrantTypes.Implicit,
AllowAccessTokensViaBrowser = true,
RequireConsent = false,
//RefreshTokenUsage = TokenUsage.OneTimeOnly,
AccessTokenLifetime = 3600 * 24,
RedirectUris = {
"http://localhost:3000/callback"
},
PostLogoutRedirectUris = { "http://localhost:3000/login" },
AllowedCorsOrigins = { "http://localhost:3000" },
AllowedScopes =
{
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
"aoo_api",
"Schedules.API",
"Ordering.API",
"Catalog.API"
}
},
React 中的用户管理器:
import { createUserManager } from 'redux-oidc';
import { UserManagerSettings } from 'oidc-client';
const userManagerConfig: UserManagerSettings = {
client_id: 'airvector',
redirect_uri: `${window.location.protocol}//
${window.location.hostname}${window.location.port ?
`:${window.location.port}` : ''}/callback`,
response_type: 'token id_token',
scope:"openid profile aoo_api Schedules.API Ordering.API Catalog.API",
authority: 'http://localhost:5000', // DEV
silent_redirect_uri: 'http://localhost:3000/login',
automaticSilentRenew: true,
filterProtocolClaims: true,
loadUserInfo: true,
monitorSession: true
};
const userManager = createUserManager(userManagerConfig);
export default userManager;
解决方案
推荐阅读
- python - Python中的动态对象命名和类调用
- nodes - 向匿名用户授予对节点的访问权限(在节点创建期间)
- python - 附加列表给出了不同的结果以打印结果
- python - 无法在python中连接到远程设备
- java - 如何从注册 Servlet 调度到登录 Servlet POST 方法
- javascript - 从数据列表中选择的查看选项
- ios - 如何在搜索栏上设置更改占位符颜色?
- c - 将可变长度数组声明为宏
- javascript - 如何有效地对 JavaScript 和 CSS 文件进行版本控制?
- netbeans - 为什么我不能在 netbeans 8.2 中使用调色板?