I am using angular and trying to implement azure ad b2c connection. But for accessing an API I am calling acquiretokensilent to get the cached token. But it is providing me a new set of tokens every single time even though the accesstoken hasn't expired yet. Here is the code.
getDataFromjQuery(){
var account = this.authService.instance.getAccountByUsername('[email protected]');
const accessTokenRequest = {
scopes: ["https://*********.com/api/FullAccess"],
account: account || this.authService.instance.getAllAccounts()[0],
forceRefresh: false,
cacheLookupPolicy: CacheLookupPolicy.Default,
refreshTokenExpirationOffsetSeconds: 7200
};
this.authService.acquireTokenSilent(accessTokenRequest).subscribe( (accessTokenReponse) => {
if(accessTokenReponse != null) {
// Acquire token silent success
let accessToken = accessTokenReponse.accessToken;
// Call your API with token
console.log("We got the token! hahaha: " + accessToken);
const headers = {
Authorization: `Bearer ${accessToken}`,
};
$.ajax({
url: this.apiUrl,
method: 'GET',
headers: headers,
dataType: 'json',
}).then((data)=>{console.log(data)});
}
})
I am expecting to get new accesstoken only if the current one has expired. But it is providing me a new pair without even checking the cache.