Skip to content
New issue

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

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

Already on GitHub? # to your account

Add Dribbble provider #69

Merged
merged 3 commits into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ For a flexible OAuth 2.0 client, see [`oslo/oauth2`](http://github.com/pilcrowon
- Box
- Coinbase
- Discord
- Dribbble
- Dropbox
- Facebook
- Figma
Expand Down
1 change: 1 addition & 0 deletions docs/malta.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
["Box", "/providers/box"],
["Coinbase", "/providers/coinbase"],
["Discord", "/providers/discord"],
["Dribbble", "/providers/dribbble"],
["Dropbox", "/providers/dropbox"],
["Facebook", "/providers/facebook"],
["Figma", "/providers/figma"],
Expand Down
35 changes: 35 additions & 0 deletions docs/pages/providers/dribbble.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
title: "Dribbble"
---

# Dribbble

For usage, see [OAuth 2.0 provider](/guides/oauth2).

```ts
import { Dribbble } from "arctic";

const dribbble = new Dribbble(clientId, clientSecret, redirectURI);
```

```ts
const url: URL = await dribbble.createAuthorizationURL(state, {
// optional
scopes
});
const tokens: DribbbleTokens = await dribbble.validateAuthorizationCode(code);
```

## Get user profile

Use the [`/user` endpoint](https://developer.dribbble.com/v2/user).

```ts
const tokens = await dribbble.validateAuthorizationCode(code);
const response = await fetch("https://api.dribbble.com/v2/user", {
headers: {
Authorization: `Bearer ${tokens.accessToken}`
}
});
const user = await response.json();
```
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export { Bitbucket } from "./providers/bitbucket.js";
export { Box } from "./providers/box.js";
export { Coinbase } from "./providers/coinbase.js";
export { Discord } from "./providers/discord.js";
export { Dribbble } from "./providers/dribbble.js";
export { Dropbox } from "./providers/dropbox.js";
export { Facebook } from "./providers/facebook.js";
export { Figma } from "./providers/figma.js";
Expand Down Expand Up @@ -45,6 +46,7 @@ export type { BitbucketTokens } from "./providers/bitbucket.js";
export type { BoxTokens } from "./providers/box.js";
export type { CoinbaseTokens } from "./providers/coinbase.js";
export type { DiscordTokens } from "./providers/discord.js";
export type { DribbbleTokens } from "./providers/dribbble.js";
export type { DropboxRefreshedTokens, DropboxTokens } from "./providers/dropbox.js";
export type { FacebookTokens } from "./providers/facebook.js";
export type { FigmaRefreshedTokens, FigmaTokens } from "./providers/figma.js";
Expand Down
45 changes: 45 additions & 0 deletions src/providers/dribbble.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { OAuth2Client } from "oslo/oauth2";

import type { OAuth2Provider } from "../index.js";

const authorizeEndpoint = "https://dribbble.com/oauth/authorize";
const tokenEndpoint = "https://dribbble.com/oauth/token";

export class Dribbble implements OAuth2Provider {
private client: OAuth2Client;
private clientSecret: string;

constructor(clientId: string, clientSecret: string, redirectURI: string) {
this.client = new OAuth2Client(clientId, authorizeEndpoint, tokenEndpoint, {
redirectURI
});
this.clientSecret = clientSecret;
}

public async createAuthorizationURL(
state: string,
options?: {
scopes?: string[];
}
): Promise<URL> {
return await this.client.createAuthorizationURL({
state,
scopes: options?.scopes ?? []
});
}

public async validateAuthorizationCode(code: string): Promise<DribbbleTokens> {
const result = await this.client.validateAuthorizationCode(code, {
authenticateWith: "request_body",
credentials: this.clientSecret
});
const tokens: DribbbleTokens = {
accessToken: result.access_token
};
return tokens;
}
}

export interface DribbbleTokens {
accessToken: string;
}