diff --git a/controller/discord.ts b/controller/discord.ts new file mode 100644 index 0000000..935fa4b --- /dev/null +++ b/controller/discord.ts @@ -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); \ No newline at end of file