Skip to content

Commit

Permalink
Fix refresh flow of some built-in OAuthServices
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieudutour committed Feb 6, 2024
1 parent deb9cfb commit d4fc5e4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
4 changes: 4 additions & 0 deletions docs/utils-reference/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ npm install --save @raycast/utils

## Changelog

### v1.12.3

- Fixed bodyEncoding for some built-in OAuthServices.

### v1.12.2

- Fixed types for `OAuthService.slack`.
Expand Down
4 changes: 2 additions & 2 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.2",
"version": "1.12.3",
"description": "Set of utilities to streamline building Raycast extensions",
"author": "Raycast Technologies Ltd.",
"homepage": "https://developers.raycast.com/utils-reference",
Expand Down
17 changes: 12 additions & 5 deletions src/oauth/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type BaseProviderOptions = {
personalAccessToken?: string;
refreshTokenUrl?: string;
onAuthorize?: (params: OnAuthorizeParams) => void;
bodyEncoding?: "json" | "url-encoded";
};

export type ProviderWithDefaultClientOptions = BaseProviderOptions & Partial<ClientOptions>;
Expand Down Expand Up @@ -61,10 +62,11 @@ export const asanaService = (options: ProviderWithDefaultClientOptions) =>
clientId: options.clientId ?? PROVIDERS_CONFIG.asana.clientId,
authorizeUrl: options.authorizeUrl ?? "https://asana.oauth.raycast.com/authorize",
tokenUrl: options.tokenUrl ?? "https://asana.oauth.raycast.com/token",
refreshTokenUrl: options.refreshTokenUrl,
refreshTokenUrl: options.refreshTokenUrl ?? "https://asana.oauth.raycast.com/refresh-token",
scope: options.scope,
personalAccessToken: options.personalAccessToken,
onAuthorize: options.onAuthorize,
bodyEncoding: options.bodyEncoding
});

export const githubService = (options: ProviderWithDefaultClientOptions) =>
Expand All @@ -79,10 +81,11 @@ export const githubService = (options: ProviderWithDefaultClientOptions) =>
clientId: options.clientId ?? PROVIDERS_CONFIG.github.clientId,
authorizeUrl: options.authorizeUrl ?? "https://github.oauth.raycast.com/authorize",
tokenUrl: options.tokenUrl ?? "https://github.oauth.raycast.com/token",
refreshTokenUrl: options.refreshTokenUrl,
refreshTokenUrl: options.refreshTokenUrl ?? "https://github.oauth.raycast.com/refresh-token",
scope: options.scope,
personalAccessToken: options.personalAccessToken,
onAuthorize: options.onAuthorize,
bodyEncoding: options.bodyEncoding
});

export const googleService = (options: ProviderOptions) =>
Expand All @@ -100,7 +103,7 @@ export const googleService = (options: ProviderOptions) =>
refreshTokenUrl: options.tokenUrl,
scope: options.scope,
personalAccessToken: options.personalAccessToken,
bodyEncoding: "url-encoded",
bodyEncoding: options.bodyEncoding ?? "url-encoded",
onAuthorize: options.onAuthorize,
});

Expand All @@ -120,6 +123,7 @@ export const jiraService = (options: ProviderOptions) =>
scope: options.scope,
personalAccessToken: options.personalAccessToken,
onAuthorize: options.onAuthorize,
bodyEncoding: options.bodyEncoding
});

export const linearService = (options: ProviderWithDefaultClientOptions) =>
Expand All @@ -134,11 +138,13 @@ export const linearService = (options: ProviderWithDefaultClientOptions) =>
clientId: options.clientId ?? PROVIDERS_CONFIG.linear.clientId,
authorizeUrl: options.authorizeUrl ?? "https://linear.oauth.raycast.com/authorize",
tokenUrl: options.tokenUrl ?? "https://linear.oauth.raycast.com/token",
refreshTokenUrl: options.refreshTokenUrl ?? "https://linear.oauth.raycast.com/refresh-token",
scope: options.scope,
extraParameters: {
actor: "user",
},
onAuthorize: options.onAuthorize,
bodyEncoding: options.bodyEncoding
});

export const slackService = (options: ProviderWithDefaultClientOptions) =>
Expand All @@ -153,12 +159,13 @@ export const slackService = (options: ProviderWithDefaultClientOptions) =>
clientId: options.clientId ?? PROVIDERS_CONFIG.slack.clientId,
authorizeUrl: options.authorizeUrl ?? "https://slack.oauth.raycast.com/authorize",
tokenUrl: options.tokenUrl ?? "https://slack.oauth.raycast.com/token",
refreshTokenUrl: options.tokenUrl ?? "https://slack.oauth.raycast.com/refresh-token",
scope: "",
extraParameters: {
user_scope: options.scope,
},
personalAccessToken: options.personalAccessToken,
bodyEncoding: "url-encoded",
bodyEncoding: options.tokenUrl ? options.bodyEncoding ?? "url-encoded" : "json",
onAuthorize: options.onAuthorize,
});

Expand All @@ -177,6 +184,6 @@ export const zoomService = (options: ProviderOptions) =>
refreshTokenUrl: options.refreshTokenUrl,
scope: options.scope,
personalAccessToken: options.personalAccessToken,
bodyEncoding: "url-encoded",
bodyEncoding: options.bodyEncoding ?? "url-encoded",
onAuthorize: options.onAuthorize,
});

0 comments on commit d4fc5e4

Please sign in to comment.