Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
570
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     const encodeForm = data => {
  2.       return Object.keys(data)
  3.         .map(
  4.           key => encodeURIComponent(key) + "=" + encodeURIComponent(data[key])
  5.         )
  6.         .join("&");
  7.     };
  8.  
  9.     const creds = await btoa(
  10.       `${process.env.DISCORD_CLIENT_ID}:${process.env.DISCORD_CLIENT_SECRET}`
  11.     );
  12.  
  13.     const redirect = encodeURIComponent("http://localhost:8080/");
  14.  
  15.     const formData = {
  16.       grant_type: "authorization_code",
  17.       code: code,
  18.       redirect_uri: redirect,
  19.       scope: "identify"
  20.     };
  21.  
  22.     axios.post(
  23.       `https://discordapp.com/api/oauth2/token`,
  24.       encodeForm(formData),
  25.       {
  26.         headers: {
  27.           "Content-Type": "application/x-www-form-urlencoded",
  28.           Authorization: `Basic ${creds}`
  29.         }
  30.       }
  31.     );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement