Created the discord controller
This commit is contained in:
parent
bb23b7ce01
commit
846ed71982
21
controller/discord.ts
Normal file
21
controller/discord.ts
Normal 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);
|
Loading…
x
Reference in New Issue
Block a user