Created the discord controller

This commit is contained in:
Mathias Wagner 2022-09-08 23:54:23 +02:00
parent bb23b7ce01
commit 846ed71982
Signed by: Mathias
GPG Key ID: B8DC354B0A1F5B44

21
controller/discord.ts Normal file
View File

@ -0,0 +1,21 @@
import DiscordOauth2 from 'discord-oauth2';
const oauth = new DiscordOauth2();
/**
* Retrieves an access & refresh token from the discord api
* @param code The authorization code from the callback
*/
export const createTokenByCode = (code: string) => oauth.tokenRequest({
grantType: "authorization_code",
scope: "identify guilds",
clientId: process.env.DC_CLIENT,
clientSecret: process.env.DC_SECRET,
redirectUri: process.env.DC_REDIRECT_URI,
code
});
/**
* Gets user information from the discord api
* @param token The access token of the user
*/
export const getUser = (token: string) => oauth.getUser(token);