我正在使用IDP获取访问令牌,然后使用该访问令牌访问API。我正在遵循授权码授予类型。首先,我成功调用了授权端点并获得了代码。然后,在我使用该代码获取访问令牌之后。当我获取访问令牌时,令牌调用将被取消。请参考下图。
请参考以下代码。
handleAuthentication() {
const authResult = new URLSearchParams(window.location.search);
console.log(authResult);
if(authResult){
const code=authResult.get('code')
var tokenURL="https://localhost:8243/token?grant_type=authorization_code&code="+code+"&redirect_uri=http://localhost:3000/callback";
axios.post(tokenURL,{ "Authorization": "Basic QjNLa0lMamtQTHNtWGhxQ2lZNWJYSGxFb3pNYTpFUG5ubkR1Zld6dENubmVmVE9hNll5Tm9jMFVh"})
.then(response =>{
console.log('Success', response);
if(response && response.access_token){
localStorage.setItem('isLoggedIn', 'true');
let expiresAt = (authResult.expires_in * 1000) + new Date().getTime();
this.expiresAt = expiresAt;
this.accessToken = authResult.access_token;
localStorage.setItem('expiresAt',expiresAt);
localStorage.setItem('accessToken', this.accessToken);
} else {
console.log("An error occurred while authentication.");
alert(`Error: Check the console for further details.`);
}
})
.catch(e=>{
console.log("Error",e);
})
}
为什么令牌通话被取消。感谢任何反馈。