diff --git a/src/connections/Facebook/index.ts b/src/connections/Facebook/index.ts
index 80950a8e..2d490c63 100644
--- a/src/connections/Facebook/index.ts
+++ b/src/connections/Facebook/index.ts
@@ -1,6 +1,7 @@
import {
Config,
ConnectedAccount,
+ ConnectedAccountCommonOAuthTokenResponse,
ConnectionCallbackSchema,
ConnectionLoader,
DiscordApiErrors,
@@ -9,14 +10,6 @@ import fetch from "node-fetch";
import Connection from "../../util/connections/Connection";
import { FacebookSettings } from "./FacebookSettings";
-interface OAuthTokenResponse {
- access_token: string;
- token_type: string;
- scope: string;
- refresh_token?: string;
- expires_in?: number;
-}
-
export interface FacebookErrorResponse {
error: {
message: string;
@@ -81,7 +74,10 @@ export default class FacebookConnection extends Connection {
return url.toString();
}
- async exchangeCode(state: string, code: string): Promise<string> {
+ async exchangeCode(
+ state: string,
+ code: string,
+ ): Promise<ConnectedAccountCommonOAuthTokenResponse> {
this.validateState(state);
const url = this.getTokenUrl(code);
@@ -93,10 +89,15 @@ export default class FacebookConnection extends Connection {
},
})
.then((res) => res.json())
- .then((res: OAuthTokenResponse & FacebookErrorResponse) => {
- if (res.error) throw new Error(res.error.message);
- return res.access_token;
- })
+ .then(
+ (
+ res: ConnectedAccountCommonOAuthTokenResponse &
+ FacebookErrorResponse,
+ ) => {
+ if (res.error) throw new Error(res.error.message);
+ return res;
+ },
+ )
.catch((e) => {
console.error(
`Error exchanging token for ${this.id} connection: ${e}`,
@@ -124,8 +125,8 @@ export default class FacebookConnection extends Connection {
params: ConnectionCallbackSchema,
): Promise<ConnectedAccount | null> {
const userId = this.getUserId(params.state);
- const token = await this.exchangeCode(params.state, params.code!);
- const userInfo = await this.getUser(token);
+ const tokenData = await this.exchangeCode(params.state, params.code!);
+ const userInfo = await this.getUser(tokenData.access_token);
const exists = await this.hasConnection(userId, userInfo.id);
|