This is a sample app on how you can implement discord oauth2 on the backend.
There is a clean version of this code in which all the comments from index.js has been removed which you can clone if you want to work with the code and not want to clean up the comments manually.
To clone just that branch, you can use degit. By using degit, it won't clone the git history and the other branches, so it will be much cleaner and quicker.
npx degit KrishGarg/OAuth2-Discord-ExpressJs#clean
Variable | Default | Description | Required? |
---|---|---|---|
CLIENT_ID | None | Client ID of the application. | Yes |
CLIENT_SECRET | None | Client Secret of the application. | Yes |
OAUTH2_URL | None | OAuth2 URL of the application. | Yes |
REDIRECT_URL | None | {api_host}/api/discord/callback | Yes |
SCOPE | None | Scoped you want to use. Example: guilds%20identify | Yes |
PORT | 3000 | The port on which the app would listen to. | No |
You can get all the above constants from discord developer portal. For detailed information on the available scopes, you can checkout the discord documentation.
The index.js file is well commented/documented.