1.4.0 • Published 3 years ago

disc-auth.js v1.4.0

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

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 secret
  • id - The Client's id
  • uri - The redirect URI for your OAuth2 app
  • scopes - Scopes for your app. Must be seperated by a space " " (eg. "identify guilds") MUST NOT BE AN ARRAY
  • debug - Default is false. When turned into true it'll log everything that makes a request to the API

Properties

  • client - This stores client id's secret's and the uri
    • secret - The Client's secret
    • id - The Client's id
    • uri - The redirect URI for your OAuth2 app
  • scopes - The scopes for the OAuth2 app (eg. "identify guilds")
  • debug - Default is false. When turned into true it'll log everything that makes a request to the API
  • app - This contains information about the app and that information will be the User and the access_token and refresh_token
    • tokens
      • access_token - The access_token for the app
      • refresh_token - The refresh_token used for when refreshing the current access_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

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

Properties

  • raw - The raw data of a user.
  • id - The id of the user
  • username - The username of the user (eg. Slay)
  • discriminator - The discriminator of the user (eg. 0098)
  • tag - Combined with the username and the discriminator. Seperated by a "#" (eg. Slay#0098)
  • email - The email of the user (May return null if the app has identify scope but not email)
  • 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.

1.4.0

3 years ago

1.3.0

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago