Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OAuth utils #20

Merged
merged 7 commits into from
Jan 24, 2024
Merged

Add OAuth utils #20

merged 7 commits into from
Jan 24, 2024

Conversation

thomaslombart
Copy link
Contributor

@thomaslombart thomaslombart commented Dec 28, 2023

Add a set of OAuth utils to make it easier to authenticate with services in Raycast extensions. This PR introduces the following utils:

  • withAccessToken along with getAccessToken to make it easy to fetch and get an authentication token in commands.
  • OAuthService along with built-in providers (e.g GitHub, Linear, etc.) to make it easy to integrate with OAuth providers.

@thomaslombart thomaslombart self-assigned this Dec 28, 2023
@thomaslombart thomaslombart force-pushed the f/oauth-util branch 4 times, most recently from f0ba3f8 to a6403b1 Compare January 10, 2024 10:23
@thomaslombart thomaslombart marked this pull request as ready for review January 10, 2024 10:27
});
```

## Example
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's put this above the ### properties

const accessToken = await oauthService.authorize();
```

### Properties
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename this to ## Built-in Services

##### Signature

```ts
const asana: OAuthService
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this any useful? Could we replace it with a description like [OauthService](...) to authenticate with [Asana](...) with the correct links?

@@ -0,0 +1,62 @@
# OAuth

Authenticating with OAuth in Raycast extensions is tedious. So we've built a set of utilities to make that task way easier. There's two part to our utilities:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's now blame Raycast, it's the case everywhere 😓

Suggested change
Authenticating with OAuth in Raycast extensions is tedious. So we've built a set of utilities to make that task way easier. There's two part to our utilities:
Dealing with OAuth can be tedious. So we've built a set of utilities to make that task way easier. There's two part to our utilities:


Authenticating with OAuth in Raycast extensions is tedious. So we've built a set of utilities to make that task way easier. There's two part to our utilities:

1. Authenticating with the service using [OAuthService](utils-reference/oauth/OAuthService.md) and some third-party providers (e.g GitHub with `OAuthService.github`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
1. Authenticating with the service using [OAuthService](utils-reference/oauth/OAuthService.md) and some third-party providers (e.g GitHub with `OAuthService.github`)
1. Authenticating with the service using [OAuthService](utils-reference/oauth/OAuthService.md) or some built-in providers (e.g GitHub with `OAuthService.github`)

Returns the wrapped component if used in a `view` command or the wrapped function if used in a `no-view` command.

{% hint style="info" %}
Note that the access token isn't injected into the wrapped component props. Instead, it's been set as a global variable that you can get with `getAccessToken`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add a link to the getAccessToken doc here

export default withAccessToken({ authorize })(AuthorizedComponent);
```

Note that it also works for `no-view` commands as stated above:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's use tabs like we do in other pages

type OnAuthorizeParams = {
token: string;
type: OAuthType;
idToken: string | null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
idToken: string | null;
idToken: string | null; // only present if `options.client` has been provided

@@ -39,7 +39,7 @@ export function getProgressIcon(
color: Color | string = Color.Red,
options?: { background?: Color | string; backgroundOpacity?: number },
): Image.Asset {
const background = options?.background || (environment.appearance === "light" ? "black" : "white");
const background = options?.background || (environment.theme === "light" ? "black" : "white");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why? it's deprecated now

* ```
*
* @param {object} options - Configuration options for the token acquisition.
* @param {() => Promise<string>} options.authorize - A function to retrieve an OAuth token.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add this doc to WithAccessTokenParameters as well

Copy link
Member

@mathieudutour mathieudutour left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright this is looking good 🙌

@thomaslombart thomaslombart merged commit 5885ddc into main Jan 24, 2024
1 check passed
@thomaslombart thomaslombart deleted the f/oauth-util branch January 24, 2024 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants