1.0.3 • Published 4 years ago
dcord-oauth v1.0.3
dcord-oauth
A NPM Package for handling discord OAuth2 Requests!
Documentation
const DiscordOAuth = require("dcord-oauth");
const OAuth = new DiscordOAuth.OAuth({
clientID: "CLIENT_ID",
clientSecret: "CLIENT_SECRET",
scope: ["identify"],
callback: "http://localhost/callback"
})
- Getting the OAuth code
- In this example i'll be using an express server, but you can use any.
router.get('/login', (req, res) => {
res.redirect(OAuth.getUrl())
});
- Getting the user data
router.get('/callback', async (req, res) => {
let code = req.query.code
if (code) {
let codes = await OAuth.getTokens(code)
let User = new DiscordOAuth.User(codes.access_token)
let user = await User.getUser();
let guilds = await User.getGuilds();
res.json({guilds: guilds, user: user})
}else{
res.sendStatus(400)
}
});
- That's pretty much it for the basics. Feel free to make PR's to make this package better!