I'm trying to make GET request to ("me/todo/lists") endpoint for M365. It works initially after a fresh authentication and acquiring the access-token.
It even works when the access token is saved and the request is made after a couple of minutes, meaning that the code for using the saved access token works.
But when I try to call the API after sometime by storing the access token, I get the error: "Error: Access token has expired or is not yet valid"
Here's the code for making the request with the saved access token
public async getTaskLists(accessToken: string) {
class MyAuthenticationProvider implements AuthenticationProvider {
/**
* This method will get called before every request to the msgraph server
* This should return a Promise that resolves to an accessToken (in case of success) or rejects with error (in case of failure)
* Basically this method will contain the implementation for getting and refreshing accessTokens
*/
public async getAccessToken(): Promise<string> {
return accessToken;
}
}
const options = {
authProvider: new MyAuthenticationProvider(), // An instance created from previous step
};
const client = Client.initWithMiddleware(options);
//this part fetches task-lists from M365 and populates them into placed in a tree-view using registerTreeDataProvider
let dataObject = [];
let children: string[] = [];
try {
let taskList = await client.api("/me/todo/lists").get();
console.log(taskList);
} catch (error) {
console.log(error);
}
}
}