Skip to content

Commit

Permalink
fourth batch
Browse files Browse the repository at this point in the history
  • Loading branch information
bcdrme committed Jan 19, 2025
1 parent 37c87ef commit 1250660
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/main/oauth2/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export async function authenticate(): Promise<TokenResponse> {
log.error(error);
throw new Error(error);
}
// Refresh token is mandatory for this app to work
const { access_token, refresh_token, expires_in } = await tokenResponse.json();
if (!access_token || !refresh_token) {
const responseText = await tokenResponse.text();
Expand Down Expand Up @@ -131,15 +132,18 @@ export async function renewAccessToken(refreshToken: string): Promise<TokenRespo
throw new Error(error);
}
const { access_token, refresh_token, expires_in } = await tokenResponse.json();
if (!access_token || !refresh_token) {
if (!access_token || !expires_in) {
const error = "Invalid OAuth2 token response";
log.error(error);
throw new Error(error);
}
if (!refresh_token) {
log.info("No new refresh token in token response, keeping the current one.");
}
log.debug("Renewed access token");
return {
token: access_token,
refreshToken: refresh_token,
refreshToken: refresh_token ? refresh_token : refreshToken,
expiresIn: expires_in,
};
}
Expand Down

0 comments on commit 1250660

Please sign in to comment.