1.0.3 • Published 5 years ago
better-disco-oauth v1.0.3
Better-Disco-Oauth
This module is based off of the original Disco-Oauth package made by hsbhatia7. It can be found here.
Installation
npm i better-disco-oauth --save
Setup
const oauth = require('better-disco-oauth')
let oAuth = new oauth('bot-id', 'bot-secret', false, false, false, false)
/*
bot id &
bot secret can be found at https://discordapp.com/developers/applications
auto accept, is false by default, if set to true, will add &prompt=none to the end of your oauth url
cacheUsers, false by default, if set to true the users information will be stored in the database and will be retreived instead of making an api request each time
cacheGuilds, same as above
cacheConnections, same as above
*/
oAuth.setScopes(['identify', 'guilds', 'connections'])
//can be any or all of the scopes listed on the oauth page of the developer docs
oAuth.setRedirect('https://www.example.com/discord-login')
//replace this with your website's url
//it must be added as a redirect url on your application at https://discordapp.com/developers/applications
oAuth.getAuthCodeLink()
//gives you the link to send users to
oAuth.getAccess(code)
//after you have sent them to that url, when they have authorized the application they will be directed back to the url like so
//https://www.example.com/discord-login?code=theirAuthorizationCode
//this is the code that you want to use to getAccess
//returns a key that you should store in cookies or somewhere else
oAuth.getAccessObject(key)
//use the key returned from getAccess to view the information returned from discord, eg access token, scopes etc
oAuth.refreshAccess(key)
//updates the information in the database for a new key when the old one expires
oAuth.getAuthorizedUserConnections(key)
//returns a list of all of their connections
//requires you to have added 'connections' into your auth scopes
oAuth.getAuthorizedUser(key)
//returns user information such as id, username, discrim, avatar, nitro status, email (if included in auth scope)
oAuth.getAuthorizedUserGuilds(key)
//returns users guilds if guilds scope is included
oAuth.deleteObject(key)
//deletes an object from the database, use this for logging users out for security
oAuth.getKeyFromID(id)
//if a user has logged into your dashboard previously, you are able to get their key using this method
//this is meant for helping purposes, not to abuse this package