所以我有一个使用 oauth (使用 okta)的工作 React 应用程序,但我有一个问题。
当我在授权服务器中更改我的声明时,应用程序不会看到此内容,直到令牌过期或我注销并再次登录。
但是当刷新页面(F5)时,我
getUser()
函数返回正确的声明,但令牌未更新。
有没有办法告诉 okta 客户端获取新令牌?
我正在使用 okta-auth-js。
谢谢
所以我发现
getWithoutPrompt()
https://github.com/okta/okta-auth-js/blob/master/README.md#tokengetwithoutpromptoptions
这使我能够在使用
getUser()
函数检测到更改时获取新令牌
authClient.token.getWithoutPrompt({
responseType: 'id_token', // or array of types
sessionToken: 'testSessionToken' // optional if the user has an existing Okta session
scopes: [
'openid',
'email',
'profile'
],
state: '8rFzn3MH5q',
nonce: '51GePTswrm',
// Use a custom IdP for social authentication
idp: '0oa62b57p7c8PaGpU0h7'
})
.then(function(res) {
var tokens = res.tokens;
// Do something with tokens, such as
authClient.tokenManager.setTokens(tokens);
})
.catch(function(err) {
// handle OAuthError or AuthSdkError (AuthSdkError will be thrown if app is in OAuthCallback state)
});