Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save felixfong227/74c20d7b34b12c991f110e3bde2bd53c to your computer and use it in GitHub Desktop.
Save felixfong227/74c20d7b34b12c991f110e3bde2bd53c to your computer and use it in GitHub Desktop.

A Step by step guide for settings up Discord OAuth

⚠️ Only applicable for version v1.0

https://camo.githubusercontent.com/e4f3b15ce5cbe716386b6a90486929208e8c0598/68747470733a2f2f692e696d6775722e636f6d2f544139737730432e706e67


Step 1: Identify your machine's domain

If you are working on your local machine, your host domain will usually either be localhost or 127.0.0.1

If the address localhost isn't working you, here is a brilliant Stackoverflow post to explain and teach you how to config one for yourself Stackoverflow Post

Host File Respectly On OSs

OS File Location
Linux /etc/hosts
Windows C:\Windows\System32\drivers\etc\hosts
MacOS /etc/hosts

Step 2: Craft Your Own Redirect URI

In order to allow Discord to give out user's login credential without the user themself actually providing any secrets to third parties, Discord and many other services are using what known as an "OAuth Protocol" to give third parties application or services to permissions on behalf of the user themself to access the host services resource, in this case, we are accessing user's public information and their communities servers

Your RedirectURI should look something like this: {HOST}:{?PORT}/authorize/callback

Examples:

For a typical local machine: http://localhost:3000/authorize/callback For a Heroku pod: https://your-app-name.heroku.app/authorize/callback

Step 3: Provide Your Informations To Discord

⚠️ In this step, I am assuming you have already created a Discord Application

  1. please navigate to the Discord Developer Web Console Link
  2. Click and open your testing bot It should look something like this
  3. Click on the "Oauth2" button on the side menu
  4. Click on the "Add Redirect" button
  5. And paste your redirect URI into the input box
  6. And once you have pasted the URI, just click "Save Changes"
  7. Navigate back to your code editor, and open the ".env" file
  8. Add a new variable named DISCORD_REDIRECT_URI and the value is your redirect URI

And you are pretty much done 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment