orels1 / discord-token-generator

An example discord oauth2 token generator
116 stars 75 forks source link

HELP #7

Open BallisticOK opened 4 years ago

BallisticOK commented 4 years ago

hey i get this image

when i try to click the login how and where do i fix this

orels1 commented 4 years ago

This repo is really old, and it seems like URLs have changed since. I might try to update the post when i get a chance, but you might try changing

https://discordapp.com/api/oauth2/authorize

in api/discord.js to

https://discord.com/api/oauth2/authorize

im not sure that's enough tho

TheCuteFoxxy commented 3 years ago

You can generate the OAuth2 link from the dev portal. Replace the original with this and it will work. https://discordapp.com/api/oauth2/authorize?client_id=${CLIENT_ID}&scope=identify&response_type=code&redirect_uri=${redirect}

alaninnovates commented 3 years ago

This repo is really old, and it seems like URLs have changed since. I might try to update the post when i get a chance, but you might try changing

https://discordapp.com/api/oauth2/authorize

in api/discord.js to

https://discord.com/api/oauth2/authorize

im not sure that's enough tho

The error seems to be because they did not set the uri in the dashboard. and yes, the uri's have changed":

const redirUri = 'http://localhost:[port]/api/discord/callback';
router.get(
    '/callback',
    catchAsyncErrors(async (req, res) => {
        if (!req.query.code) throw new Error('NoCodeProvided');
        const code = req.query.code;
        const creds = btoa(`${clientId}:${clientSecret}`);
        const data = {
            grant_type: 'authorization_code',
            client_id: clientId,
            client_secret: clientSecret,
            code,
            redirect_uri: redirUri,
            scope: 'identify',
        };
        const response = await fetch(
            `https://discord.com/api/oauth2/token`,
            {
                method: 'POST',
                headers: {
                    Authorization: `Basic ${creds}`,
                    'Content-type': `application/x-www-form-urlencoded`,
                },
                body: new URLSearchParams(data),
            },
        );
        const json = await response.json();
        console.log(json);
        res.redirect(`/?token=${json.access_token}`);
    }),
);

it changed to https://discord.com/api/oauth2/token EDIT: i forgot to mention but discordapp is going to get disabled soon