mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-09-10 21:26:08 -05:00
Token call behind GW
This commit is contained in:
@@ -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=
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user