diff options
author | Emma [it/its]@Rory& <root@rory.gay> | 2023-12-11 01:12:54 +0100 |
---|---|---|
committer | Emma [it/its]@Rory& <root@rory.gay> | 2023-12-11 01:12:54 +0100 |
commit | 0a8ceb9e6349284e75545a01ffad608b020f78e2 (patch) | |
tree | 17a9163f963eddabf9168b0b630096b2f7535b64 /src/connections/EpicGames/index.ts | |
parent | Prettier: use editorconfig (diff) | |
download | server-dev/emma-refactors.tar.xz |
Actually run prettier dev/emma-refactors
Diffstat (limited to 'src/connections/EpicGames/index.ts')
-rw-r--r-- | src/connections/EpicGames/index.ts | 33 |
1 files changed, 10 insertions, 23 deletions
diff --git a/src/connections/EpicGames/index.ts b/src/connections/EpicGames/index.ts index e5b2d336..6c36b3e1 100644 --- a/src/connections/EpicGames/index.ts +++ b/src/connections/EpicGames/index.ts @@ -33,8 +33,7 @@ export interface UserResponse { preferredLanguage: string; } -export interface EpicTokenResponse - extends ConnectedAccountCommonOAuthTokenResponse { +export interface EpicTokenResponse extends ConnectedAccountCommonOAuthTokenResponse { expires_at: string; refresh_expires_in: number; refresh_expires_at: string; @@ -47,17 +46,12 @@ export default class EpicGamesConnection extends Connection { public readonly id = "epicgames"; public readonly authorizeUrl = "https://www.epicgames.com/id/authorize"; public readonly tokenUrl = "https://api.epicgames.dev/epic/oauth/v1/token"; - public readonly userInfoUrl = - "https://api.epicgames.dev/epic/id/v1/accounts"; + public readonly userInfoUrl = "https://api.epicgames.dev/epic/id/v1/accounts"; public readonly scopes = ["basic profile"]; settings: EpicGamesSettings = new EpicGamesSettings(); init(): void { - const settings = - ConnectionLoader.getConnectionConfig<EpicGamesSettings>( - this.id, - this.settings, - ); + const settings = ConnectionLoader.getConnectionConfig<EpicGamesSettings>(this.id, this.settings); if (settings.enabled && (!settings.clientId || !settings.clientSecret)) throw new Error(`Invalid settings for connection ${this.id}`); @@ -79,10 +73,7 @@ export default class EpicGamesConnection extends Connection { return this.tokenUrl; } - async exchangeCode( - state: string, - code: string, - ): Promise<EpicTokenResponse> { + async exchangeCode(state: string, code: string): Promise<EpicTokenResponse> { this.validateState(state); const url = this.getTokenUrl(); @@ -90,16 +81,16 @@ export default class EpicGamesConnection extends Connection { return wretch(url.toString()) .headers({ Accept: "application/json", - Authorization: `Basic ${Buffer.from( - `${this.settings.clientId}:${this.settings.clientSecret}`, - ).toString("base64")}`, + Authorization: `Basic ${Buffer.from(`${this.settings.clientId}:${this.settings.clientSecret}`).toString( + "base64" + )}`, "Content-Type": "application/x-www-form-urlencoded", }) .body( new URLSearchParams({ grant_type: "authorization_code", code, - }), + }) ) .post() .json<EpicTokenResponse>() @@ -110,9 +101,7 @@ export default class EpicGamesConnection extends Connection { } async getUser(token: string): Promise<UserResponse[]> { - const { sub } = JSON.parse( - Buffer.from(token.split(".")[1], "base64").toString("utf8"), - ); + const { sub } = JSON.parse(Buffer.from(token.split(".")[1], "base64").toString("utf8")); const url = new URL(this.userInfoUrl); url.searchParams.append("accountId", sub); @@ -128,9 +117,7 @@ export default class EpicGamesConnection extends Connection { }); } - async handleCallback( - params: ConnectionCallbackSchema, - ): Promise<ConnectedAccount | null> { + async handleCallback(params: ConnectionCallbackSchema): Promise<ConnectedAccount | null> { const { state, code } = params; if (!code) throw new Error("No code provided"); |