Skip to content
All gists
Back to GitHub
Sign in
Sign up
Sign in
Sign up
{{ message }}
Instantly share code, notes, and snippets.
MrCrypticxDev
/
authorize.js
Created
Jun 6, 2021
Star
0
Fork
0
Star
Code
Revisions
1
Embed
What would you like to do?
Embed
Embed this gist in your website.
Share
Copy sharable link for this gist.
Clone via HTTPS
Clone with Git or checkout with SVN using the repository’s web address.
Learn more about clone URLs
Download ZIP
An easy snippet to generate your Discord bot's Bearer token!
Raw
authorize.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
const
express
=
require
(
'express'
)
;
const
app
=
express
(
)
;
const
fetch
=
require
(
'node-fetch'
)
;
const
client_id
=
'CLIENT_UI'
;
//can be found in the developer portal
const
redirect_uri
=
'http://localhost:8000/home'
;
const
client_secret
=
'CLIENT_SECRET'
;
//can be also found in the developer portal
const
scope
=
'identify'
;
// set the redirect_uri in your OAuth2 section and use the identify scope in your browser.
app
.
get
(
'/authorize'
,
(
req
,
res
)
=>
{
res
.
redirect
(
`https://discord.com/api/oauth2/authorize?client_id=
${
client_id
}
&redirect_uri=
${
encodeURIComponent
(
redirect_uri
)
}
&response_type=code&scope=
${
encodeURIComponent
(
scope
)
}
`
)
}
)
;
app
.
get
(
'/home'
,
async
(
req
,
res
)
=>
{
res
.
send
(
'Done.'
)
fetch
(
'https://discord.com/api/oauth2/token'
,
{
method
:
'POST'
,
headers
:
{
'Content-Type'
:
'application/x-www-form-urlencoded'
}
,
body
:
new
URLSearchParams
(
{
client_id
:
client_id
,
client_secret
:
client_secret
,
code
:
req
.
query
.
code
,
grant_type
:
'authorization_code'
,
redirect_uri
:
redirect_uri
,
scope
:
scope
,
}
)
,
}
)
.
then
(
response
=>
response
.
json
(
)
)
.
then
(
(
data
)
=>
console
.
log
(
data
)
)
;
}
)
;
app
.
listen
(
8000
)
;
Sign up for free
to join this conversation on GitHub
. Already have an account?
Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.