diff --git a/docs/utils-reference/getting-started.md b/docs/utils-reference/getting-started.md index 1d31c40..2716a76 100644 --- a/docs/utils-reference/getting-started.md +++ b/docs/utils-reference/getting-started.md @@ -16,6 +16,10 @@ npm install --save @raycast/utils ## Changelog +### v2.2.6 + +- Fixed an issue where refreshing OAuth tokens would fails for providers that return scope as an array instead of a string + ### v2.2.5 - Fixed an issue where `useSql` would not properly show the permission priming screen diff --git a/package-lock.json b/package-lock.json index 8810685..780fb0b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@raycast/utils", - "version": "2.2.5", + "version": "2.2.6", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@raycast/utils", - "version": "2.2.5", + "version": "2.2.6", "license": "MIT", "dependencies": { "dequal": "^2.0.3" diff --git a/package.json b/package.json index a2b3973..b0410d2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@raycast/utils", - "version": "2.2.5", + "version": "2.2.6", "description": "Set of utilities to streamline building Raycast extensions", "author": "Raycast Technologies Ltd.", "homepage": "https://developers.raycast.com/utilities/getting-started", diff --git a/src/oauth/OAuthService.ts b/src/oauth/OAuthService.ts index 6d63d83..321192d 100644 --- a/src/oauth/OAuthService.ts +++ b/src/oauth/OAuthService.ts @@ -7,6 +7,11 @@ import type { ProviderWithDefaultClientOptions, } from "./types"; +function normalizeTokenResponse(tokens: OAuth.TokenResponse): OAuth.TokenResponse { + // Some clients such as Linear can return a scope array instead of a string. + return Array.isArray(tokens.scope) ? { ...tokens, scope: tokens.scope.join(" ") } : tokens; +} + /** * Class allowing to create an OAuth service using the the PKCE (Proof Key for Code Exchange) flow. * @@ -400,8 +405,7 @@ export class OAuthService implements OAuthServiceOptions { } const tokens = this.tokenResponseParser(await response.json()); - // Some clients such as Linear can return a scope array instead of a string - return Array.isArray(tokens.scope) ? { ...tokens, scope: tokens.scope.join(" ") } : tokens; + return normalizeTokenResponse(tokens); } private async refreshTokens({ token }: { token: string }) { @@ -435,7 +439,7 @@ export class OAuthService implements OAuthServiceOptions { } else { const tokenResponse = this.tokenRefreshResponseParser(await response.json()); tokenResponse.refresh_token = tokenResponse.refresh_token ?? token; - return tokenResponse; + return normalizeTokenResponse(tokenResponse); } } }