如何使用 AWS cognito auth sdk 刷新令牌
How to refresh token using AWS coginto auth sdk
我正在开发令牌过期后刷新令牌的功能。我使用 amazon-cognito-auth-js 进行授权并检查 here 作为示例,我实现了以下方法来刷新令牌。但是它不起作用。
下面是我的代码,会话没有像我预期的那样刷新。没有 synax 错误,只是授权令牌仍然过期。
对了,我用的是react.
import { CognitoAuth } from 'amazon-cognito-auth-js';
class Main extends Component {
constructor() {
this.state = {
auth: ""
}
}
componentDidMount() {
//some logic to get the auth once user login success
//here is the logic to update the correct auth into the state
this.setState({
auth: auth
})
}
//here is the method that check the token expire or not, if expire, refresh the token and update the state
checkTokenExpiration (){
let auth = this.state.auth;
let user = auth.getCachedSession();
//ideally, there shall have the logic to check the session is expired or not
// anyidea how to write it?
auth.refreshSession(user.getRefreshToken().getToken());
this.setState({
auth:auth
})
}
}
我正在开发令牌过期后刷新令牌的功能。我使用 amazon-cognito-auth-js 进行授权并检查 here 作为示例,我实现了以下方法来刷新令牌。但是它不起作用。 下面是我的代码,会话没有像我预期的那样刷新。没有 synax 错误,只是授权令牌仍然过期。 对了,我用的是react.
import { CognitoAuth } from 'amazon-cognito-auth-js';
class Main extends Component {
constructor() {
this.state = {
auth: ""
}
}
componentDidMount() {
//some logic to get the auth once user login success
//here is the logic to update the correct auth into the state
this.setState({
auth: auth
})
}
//here is the method that check the token expire or not, if expire, refresh the token and update the state
checkTokenExpiration (){
let auth = this.state.auth;
let user = auth.getCachedSession();
//ideally, there shall have the logic to check the session is expired or not
// anyidea how to write it?
auth.refreshSession(user.getRefreshToken().getToken());
this.setState({
auth:auth
})
}
}