Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.
/ DiscordLinked Public archive

A simple plugin to connect discord to a site/app/game/etc.

License

Notifications You must be signed in to change notification settings

EvitcaStudio/DiscordLinked

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 

Repository files navigation

discord-linked

A simple plugin to connect discord to a site/app/game/etc.

Security

Warning
This plugin is currently using the Implicit Grant workflow of OAuth2.
This simply means the Client(Browser) is directly being given an access_token rather than an access_code. In a standard OAuth2 workflow that access_code would be passed to the server and the server would query Discord using that access_code to verify the user on the Server-Side rather than Client-Side. Using the Implicit Grant workflow, means it skips the server entirely.
In this workflow all data is passed directly to the Client. In this case, the data is the User Object.

Note
In the future more workflows will be allowed and will be defaulted to as the standard.
Such as the Authorization Code Grant as well as the Client Credentials Grant.
These will allow for more personalized workflows for different games/applications.
These will also allow the server to act as an intermediary, so that data doesn't have to actually be passed directly to the Client

If this workflow is an issue with security, then it is advised to not use it in it's current state. And to rather wait for the aforementioned workflows to be added.

Creating a app on discord

image

Next, you must create a discord application

image

Next, head down to the OAuth2 tab

image

Now, we see some of the information we need.

msedge_wW6s5O8jsP

We will need Client ID as well as adding some redirects.

Once you have your Client ID keep it nearby for later.
We now need to add a few redirects to our discord app, so it knows where to go.
These redirects are official Domain/IPs that are trusted within this application. Such as your site/app/game/etc.

image

Note
If you have many servers, add each Domain/IP.
These redirects also work with local hosting!

CLIENT_ID

You will need to supply your Client ID inside of discord-linked.js
Open the discord-linked.js file, and find the declaration of CLIENT_ID and input your Client ID value inside the empty string.

AUTO_AUTH

If you would like this plugin to automatically authenticate ASAP, then open the discord-linked.js file, and find the declaration of AUTO_AUTH and input the value true It is false by default.

If you do not want to automatically authenticate, then you will need to use DiscordHandler.login().

Connecting to a site/app/game/etc via your discord app

image
When connecting to a game, users will be prompted to login via discord if they are not already logged in, and will be prompted to authorize your discord app to use their data. Upon authorization, the site/app/game/etc will load.

Implementation

#INCLUDE SCRIPT discord-linked.js Vylocity only

Note
Outside of Vylocity, just include the script into the project files.

How to reference

window.DiscordUser | DiscordUser JavaScript
DiscordUser VyScript

window.DiscordHandler | DiscordHandler JavaScript
DiscordHandler VyScript

API

DiscordHandler

  • description: An instanced object that handles the authentication process of a discord user

DiscordUser

  • description: An instanced object that holds all data related to the authenticated discord user

DiscordHandler.login()

  • description: Callable API to start the authentication process of a discord user (If using AUTO_AUTH this is already called for you)

DiscordUser.getID()

  • returns: Returns the id of the logged in discord user

DiscordUser.getUserName()

  • returns: Returns the username of the logged in discord user

DiscordUser.getAvatar()

  • returns: Returns the avatar hash of the logged in discord user

DiscordUser.getBanner()

  • returns: Returns the banner hash of the logged in discord user

DiscordUser.getBannerColor()

  • returns: Returns the banner color of the logged in discord user

DiscordUser.getAccentColor()

  • returns: Returns the accent color of the logged in discord user

DiscordUser.getNitro()

  • returns: Returns the nitro membership of the logged in discord user
    0: None 1: Nitro Classic 2: Nitro

DiscordUser.get2FA()

  • returns: Returns if the logged in discord user has 2fa enabled

DiscordUser.getTag()

  • returns: Returns the tag of the logged in discord user

DiscordUser.getPublicFlags()

  • returns: Returns the public flags on the logged in discord user's account

DiscordUser.isBot()

  • returns: Returns if the logged in discord user is a bot

DiscordUser.isVerified()

  • returns: Returns if the logged in discord user has verified their email address

DiscordUser.createDiscordAvii(pWidth, pHeight, pCallback) Vylocity only

  • pWidth: The width to make the discord avatar icon
  • pHeight: The height to make the discord avatar icon
  • pCallback: A callback function that will be called when this icon is ready
  • description: Inside of the callback, the icon will be ready to be used. The atlasName will be the id of DiscordUser and the iconName will be the static name of avii

About

A simple plugin to connect discord to a site/app/game/etc.

Resources

License

Stars

Watchers

Forks

Packages

No packages published