disc-auth.js
v1.4.0
Published
A Discord OAuth2 Handler
Downloads
17
Maintainers
Readme
disc-auth.js
Installation
npm i disc-auth.js
Requirements
・You must have nodejs v14 or up
Table of Contents
Class
Client
This is the main class that you initalize to perform all the requests to the API
Constructor
new Client({
secret: "abcd",
id: "1234",
uri: "https://nevergonnagiveyou.up/login",
scopes: "identify guilds",
debug: true
})
Parameters
secret
- The Client's secretid
- The Client's iduri
- The redirect URI for your OAuth2 appscopes
- Scopes for your app. Must be seperated by a space " " (eg. "identify guilds") MUST NOT BE AN ARRAYdebug
- Default isfalse
. When turned intotrue
it'll log everything that makes a request to the API
Properties
client
- This stores client id's secret's and the urisecret
- The Client's secretid
- The Client's iduri
- The redirect URI for your OAuth2 app
scopes
- The scopes for the OAuth2 app (eg. "identify guilds")debug
- Default isfalse
. When turned intotrue
it'll log everything that makes a request to the APIapp
- This contains information about the app and that information will be the User and theaccess_token
andrefresh_token
tokens
access_token
- Theaccess_token
for the apprefresh_token
- Therefresh_token
used for when refreshing the currentaccess_token
expires_at
- When its gonna expire (With an estimated time)expires_in
- When its gonna expire (Without the estimated time)
user
- The user class. Click here
Methods
getToken()
await Client.getToken(code)
Converts a code from the query string into an access_token
Parameters
code
- The code from the query string (eg. https://idk.com/login?code=abcd)
Returns Promise
refreshToken()
await Client.refreshToken()
This refreshes an access_token
to a new one. The package automatically refresh the token when the current one expires!
Returns Promise
getUser()
await Client.getUser()
Gets the user who authenticated (Requires the identify
scope)
Returns Promise
getGuilds()
await Client.getGuilds()
Gets the user's guilds then put it in the Client.app.user.guilds
object (Must have a user authenticated/Client.app.user
exist and "guilds" scope)
Returns Promise
User
Constructor
new User(userData)
Parameters
userData
- The raw data of a user.
Properties
raw
- The raw data of a user.id
- The id of the userusername
- The username of the user (eg. Slay)discriminator
- The discriminator of the user (eg. 0098)tag
- Combined with theusername
and thediscriminator
. Seperated by a "#" (eg. Slay#0098)email
- The email of the user (May returnnull
if the app hasidentify
scope but notemail
)nitro
- The type of nitro the user currently has (eg. None or Nitro Classic or Nitro)guilds
- An array of guild objects.
Methods
displayAvatarURL
Gets a user's avatar
await User.displayAvatarURL({
dynamic: true
})
Parameters
- {}
dynamic
- Default is false, if true the format will dynamically change to gif for animated avatars.
Returns String
Support
Need help with this package? Come on down to our discord server and go to the #disc・auth under support channel to get some help.