mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-09-09 20:56:02 -05:00
Remove auth gateway code
This commit is contained in:
@@ -5,8 +5,6 @@ SESSION_SECRET=secret
|
||||
// Auth https://discord.com/developers
|
||||
DISCORD_CLIENT_ID=
|
||||
DISCORD_CLIENT_SECRET=
|
||||
AUTH_GATEWAY_PROFILE_URL=
|
||||
AUTH_GATEWAY_TOKEN_URL=
|
||||
|
||||
// Patreon integration https://www.patreon.com/portal/registration/register-clients
|
||||
PATREON_ACCESS_TOKEN=
|
||||
|
||||
@@ -29,10 +29,6 @@ const discordUserDetailsSchema = z.tuple([
|
||||
export const DiscordStrategy = () => {
|
||||
const envVars = authEnvVars();
|
||||
|
||||
const authGatewayEnabled = () => {
|
||||
return Boolean(process.env.AUTH_GATEWAY_TOKEN_URL);
|
||||
};
|
||||
|
||||
const jsonIfOk = (res: Response) => {
|
||||
if (!res.ok) {
|
||||
throw new Error(
|
||||
@@ -56,30 +52,22 @@ export const DiscordStrategy = () => {
|
||||
]);
|
||||
};
|
||||
|
||||
const fetchProfileViaGateway = (token: string) => {
|
||||
const url = `${process.env.AUTH_GATEWAY_PROFILE_URL}?token=${token}`;
|
||||
|
||||
return fetch(url).then(jsonIfOk);
|
||||
};
|
||||
|
||||
return new OAuth2Strategy(
|
||||
{
|
||||
clientId: envVars.DISCORD_CLIENT_ID,
|
||||
clientSecret: envVars.DISCORD_CLIENT_SECRET,
|
||||
|
||||
authorizationEndpoint: "https://discord.com/api/oauth2/authorize",
|
||||
tokenEndpoint:
|
||||
process.env.AUTH_GATEWAY_TOKEN_URL ||
|
||||
"https://discord.com/api/oauth2/token",
|
||||
tokenEndpoint: "https://discord.com/api/oauth2/token",
|
||||
redirectURI: new URL("/auth/callback", envVars.BASE_URL).toString(),
|
||||
|
||||
scopes: ["identify", "connections", "email"],
|
||||
},
|
||||
async ({ tokens }) => {
|
||||
try {
|
||||
const discordResponses = authGatewayEnabled()
|
||||
? await fetchProfileViaGateway(tokens.accessToken())
|
||||
: await fetchProfileViaDiscordApi(tokens.accessToken());
|
||||
const discordResponses = await fetchProfileViaDiscordApi(
|
||||
tokens.accessToken(),
|
||||
);
|
||||
|
||||
const [user, connections] =
|
||||
discordUserDetailsSchema.parse(discordResponses);
|
||||
|
||||
Reference in New Issue
Block a user