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.

Revisions

  1. felixfong227 created this gist Sep 25, 2020.
    56 changes: 56 additions & 0 deletions A Step by step guide for settings up Discord OAuth.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,56 @@
    # A Step by step guide for settings up Discord OAuth

    ⚠️ Only applicable for version `v1.0`

    ![https://camo.githubusercontent.com/e4f3b15ce5cbe716386b6a90486929208e8c0598/68747470733a2f2f692e696d6775722e636f6d2f544139737730432e706e67](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](https://serverfault.com/questions/363095/why-does-my-hostname-appear-with-the-address-127-0-1-1-rather-than-127-0-0-1-in)

    ### 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](https://discord.com/developers/applications)
    2. Click and open your testing bot
    It should look something like this
    ![](https://i.imgur.com/iEF0BvG.png)
    3. Click on the "Oauth2" button on the side menu
    ![](https://i.imgur.com/r9g7Ebj.png)
    4. Click on the "Add Redirect" button
    ![](https://i.imgur.com/e5KZjn5.png)
    5. And paste your redirect URI into the input box
    ![](https://i.imgur.com/5aJuX11.png)
    6. And once you have pasted the URI, just click "Save Changes"
    ![](https://i.imgur.com/ATZzg2Z.png)
    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
    ![](https://i.imgur.com/pcLnggo.png)

    And you are pretty much done 🎉