-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: implement anilist provider * docs: add docs for provider * minor fixes * add state --------- Co-authored-by: pilcrowOnPaper <[email protected]>
- Loading branch information
1 parent
98e91af
commit eda8396
Showing
5 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add AniList provider. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
title: "AniList" | ||
--- | ||
|
||
# AniList | ||
|
||
For usage, see [OAuth 2.0 provider](/guides/oauth2). | ||
|
||
```ts | ||
import { AniList } from "arctic"; | ||
|
||
const anilist = new AniList(clientId, clientSecret, redirectURI); | ||
``` | ||
|
||
```ts | ||
const url: URL = await anilist.createAuthorizationURL(state); | ||
const tokens: AniListTokens = await anilist.validateAuthorizationCode(code); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { OAuth2Client } from "oslo/oauth2"; | ||
import type { OAuth2Provider } from "../index.js"; | ||
|
||
const authorizeEndpoint = "https://anilist.co/api/v2/oauth/authorize"; | ||
const tokenEndpoint = "https://anilist.co/api/v2/oauth/token"; | ||
|
||
export class AniList 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): Promise<URL> { | ||
return await this.client.createAuthorizationURL({ | ||
state | ||
}); | ||
} | ||
|
||
public async validateAuthorizationCode(code: string): Promise<AniListTokens> { | ||
const result = await this.client.validateAuthorizationCode<TokenResponseBody>(code, { | ||
credentials: this.clientSecret | ||
}); | ||
const tokens: AniListTokens = { | ||
accessToken: result.access_token | ||
}; | ||
return tokens; | ||
} | ||
} | ||
|
||
interface TokenResponseBody { | ||
access_token: string; | ||
} | ||
|
||
export interface AniListTokens { | ||
accessToken: string; | ||
} |