Skip to content

Commit

Permalink
Fixed the refresh flow of OAuthService that would return outdated t…
Browse files Browse the repository at this point in the history
…okens
  • Loading branch information
mathieudutour committed Feb 5, 2024
1 parent f925535 commit c91c78c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 17 deletions.
11 changes: 10 additions & 1 deletion docs/utils-reference/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,18 @@ npm install --save @raycast/utils

## Changelog

### v1.12.1

- Fixed the refresh flow of `OAuthService` that would return outdated tokens.

### v1.12.0

- Removed some default OAuth clientIDs that could not work with generic scopes.
- Fixed `withAccessToken` when used in no-view commands.

### v1.11.1

- Fixed Google OAuth configuration
- Fixed Google OAuth configuration.

### v1.11.0

Expand Down
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@raycast/utils",
"version": "1.12.0",
"version": "1.12.1",
"description": "Set of utilities to streamline building Raycast extensions",
"author": "Raycast Technologies Ltd.",
"homepage": "https://developers.raycast.com/utils-reference",
Expand Down
14 changes: 7 additions & 7 deletions src/oauth/OAuthService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,13 @@ export class OAuthService implements OAuthServiceOptions {
const currentTokenSet = await this.client.getTokens();
if (currentTokenSet?.accessToken) {
if (currentTokenSet.refreshToken && currentTokenSet.isExpired()) {
await this.client.setTokens(
await this.refreshTokens({
token: currentTokenSet.refreshToken,
clientId: this.clientId,
tokenUrl: this.refreshTokenUrl ?? this.tokenUrl,
}),
);
const tokens = await this.refreshTokens({
token: currentTokenSet.refreshToken,
clientId: this.clientId,
tokenUrl: this.refreshTokenUrl ?? this.tokenUrl,
})
await this.client.setTokens(tokens);
return tokens.access_token;
}
return currentTokenSet.accessToken;
}
Expand Down

0 comments on commit c91c78c

Please sign in to comment.