If no expiry date then refresh the token (#7805)

This commit is contained in:
Joe Au-Yeung
2023-03-17 17:20:41 +00:00
committed by GitHub
parent 9ba13a3f3c
commit 13577a5dbe
2 changed files with 9 additions and 3 deletions
@@ -210,7 +210,13 @@ export default class Office365CalendarService implements Calendar {
}
private o365Auth = (credential: CredentialPayload) => {
const isExpired = (expiryDate: number) => expiryDate < Math.round(+new Date() / 1000);
const isExpired = (expiryDate: number) => {
if (!expiryDate) {
return true;
} else {
return expiryDate < Math.round(+new Date() / 1000);
}
};
const o365AuthCredentials = credential.key as O365AuthCredentials;
const refreshAccessToken = async (refreshToken: string) => {
@@ -240,7 +246,7 @@ export default class Office365CalendarService implements Calendar {
return {
getToken: () =>
!isExpired(o365AuthCredentials.expiry_date)
!isExpired(o365AuthCredentials.expires_in)
? Promise.resolve(o365AuthCredentials.access_token)
: refreshAccessToken(o365AuthCredentials.refresh_token),
};
@@ -1,5 +1,5 @@
export type O365AuthCredentials = {
expiry_date: number;
access_token: string;
refresh_token: string;
expires_in: number;
};