rework auth a little

This commit is contained in:
Darius
2025-10-02 23:04:31 +02:00
parent 0c54b1f776
commit fd420fa59a
13 changed files with 130 additions and 41 deletions

97
src/setup/setup-auth.ts Normal file
View File

@@ -0,0 +1,97 @@
import { exchangeCode } from "@twurple/auth";
import { Config } from "../config/config.ts";
import { TokenManager } from "../core/token-manager.ts";
import { TwitchAuth } from "../util/auth.ts";
import { logInfo } from "../util/logger.ts";
const port = 3000;
const redirectUri = `http://localhost:${port}`;
const scopes = [
"analytics:read:extensions",
"analytics:read:games",
"bits:read",
"channel:manage:ads",
"channel:read:ads",
"channel:manage:broadcast",
"channel:read:charity",
"channel:edit:commercial",
"channel:read:editors",
"channel:manage:extensions",
"channel:read:goals",
"channel:read:guest_star",
"channel:manage:guest_star",
"channel:read:hype_train",
"channel:manage:moderators",
"channel:read:polls",
"channel:manage:polls",
"channel:read:predictions",
"channel:manage:predictions",
"channel:manage:raids",
"channel:read:redemptions",
"channel:manage:redemptions",
"channel:manage:schedule",
"channel:read:stream_key",
"channel:read:subscriptions",
"channel:manage:videos",
"channel:read:vips",
"channel:manage:vips",
"clips:edit",
"moderation:read",
"moderator:manage:announcements",
"moderator:manage:automod",
"moderator:read:automod_settings",
"moderator:manage:automod_settings",
"moderator:manage:banned_users",
"moderator:read:blocked_terms",
"moderator:manage:blocked_terms",
"moderator:manage:chat_messages",
"moderator:read:chat_settings",
"moderator:manage:chat_settings",
"moderator:read:chatters",
"moderator:read:followers",
"moderator:read:guest_star",
"moderator:manage:guest_star",
"moderator:read:shield_mode",
"moderator:manage:shield_mode",
"moderator:read:shoutouts",
"moderator:manage:shoutouts",
"moderator:read:unban_requests",
"moderator:manage:unban_requests",
"user:edit",
"user:edit:follows",
"user:read:blocked_users",
"user:manage:blocked_users",
"user:read:broadcast",
"user:manage:chat_color",
"user:read:email",
"user:read:emotes",
"user:read:follows",
"user:read:moderated_channels",
"user:read:subscriptions",
"user:manage:whispers",
"channel:bot",
"channel:moderate",
"chat:edit",
"chat:read",
"user:bot",
"user:read:chat",
"user:write:chat",
"whispers:read",
"whispers:edit",
"moderator:manage:warnings",
];
const auth = new TwitchAuth(redirectUri);
const state = auth.generateState();
const authUrl = auth.getAuthorizationUrl(scopes, state);
logInfo("To authorize your Twitch bot, visit this URL:");
logInfo(authUrl);
const code = await auth.startCallbackServer(port, 120, state);
const tokenManager = new TokenManager(Config.bot_user_id);
tokenManager.createTokenFile(
await exchangeCode(Config.client_id, Config.client_secret, code, redirectUri),
);
logInfo("Token file created");