Token call behind GW

This commit is contained in:
Kalle
2023-09-26 19:44:23 +03:00
parent 21261a68bd
commit 743c721e7b
2 changed files with 8 additions and 13 deletions

View File

@@ -7,8 +7,8 @@ SESSION_SECRET=secret
// Auth https://discord.com/developers
DISCORD_CLIENT_ID=
DISCORD_CLIENT_SECRET=
AUTH_GATEWAY_URL=
AUTH_GATEWAY_SECRET=
AUTH_GATEWAY_PROFILE_URL=
AUTH_GATEWAY_TOKEN_URL=
// Patreon integration https://www.patreon.com/portal/registration/register-clients
PATREON_ACCESS_TOKEN=

View File

@@ -47,7 +47,9 @@ export class DiscordStrategy extends OAuth2Strategy<
super(
{
authorizationURL: "https://discord.com/api/oauth2/authorize",
tokenURL: "https://discord.com/api/oauth2/token",
tokenURL:
process.env["AUTH_GATEWAY_TOKEN_URL"] ??
"https://discord.com/api/oauth2/token",
clientID: envVars.DISCORD_CLIENT_ID,
clientSecret: envVars.DISCORD_CLIENT_SECRET,
callbackURL: new URL("/auth/callback", envVars.BASE_URL).toString(),
@@ -77,9 +79,7 @@ export class DiscordStrategy extends OAuth2Strategy<
}
private authGatewayEnabled() {
return Boolean(
process.env["AUTH_GATEWAY_URL"] && process.env["AUTH_GATEWAY_SECRET"],
);
return Boolean(process.env["AUTH_GATEWAY_TOKEN_URL"]);
}
private async fetchProfileViaDiscordApi(token: string) {
@@ -98,14 +98,9 @@ export class DiscordStrategy extends OAuth2Strategy<
private async fetchProfileViaGateway(token: string) {
console.log("authenticating via gateway...");
const url = `${process.env["AUTH_GATEWAY_URL"]}?token=${token}`;
const url = `${process.env["AUTH_GATEWAY_PROFILE_URL"]}?token=${token}`;
const options: RequestInit = {
method: "GET",
headers: { "X-Require-Whisk-Auth": process.env["AUTH_GATEWAY_SECRET"]! },
};
return fetch(url, options).then(this.jsonIfOk);
return fetch(url).then(this.jsonIfOk);
}
private jsonIfOk(res: Response) {