gm1003

Untitled

Nov 28th, 2020
1,034
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import json
  2. import quart
  3. import requests
  4. import aiomysql
  5.  
  6. app = quart.Quart(__name__)
  7.  
  8. API_ENDPOINT = 'https://discord.com/api/v6'
  9. CLIENT_ID = '691165150585290793'
  10. CLIENT_SECRET = 'notforyou'
  11. REDIRECT_URI = 'http://gm1003.wtf/exchange_code'
  12.  
  13. @app.route('/discord', methods=['GET'])
  14. async def redirect_to_oauth():
  15.     return quart.redirect(
  16.         f'https://discordapp.com/oauth2/authorize?client_id={CLIENT_ID}&redirect_uri={REDIRECT_URI}&response_type=code&scope=identify%20connections'
  17.     )
  18.  
  19. @app.route('/exchange_code', methods=['GET'])
  20. async def exchange_code():
  21.     data = {
  22.         'client_id': CLIENT_ID,
  23.         'client_secret': CLIENT_SECRET,
  24.         'grant_type': 'authorization_code',
  25.         'code': quart.request.args.get('code'),
  26.         'redirect_uri': REDIRECT_URI,
  27.         'scope': 'identify connections'
  28.     }
  29.  
  30.     oauth = requests.post(
  31.         f'{API_ENDPOINT}/oauth2/token',
  32.         data=data,
  33.         headers={
  34.             'Content-Type': 'application/x-www-form-urlencoded'
  35.         }
  36.     ).json()
  37.    
  38.     headers = {
  39.         'Content-Type': 'application/x-www-form-urlencoded',
  40.         'Authorization': f'Bearer {oauth["access_token"]}'
  41.     }
  42.    
  43.     user = requests.get(
  44.         f'{API_ENDPOINT}/users/@me',
  45.         headers=headers
  46.     ).json()
  47.    
  48.     connections = requests.get(
  49.         f'{API_ENDPOINT}/users/@me/connections',
  50.         headers=headers
  51.     ).json()
  52.  
  53.     for connection in connections:
  54.        
  55.         if connection['type'] == 'steam' and connection['verified']:
  56.             output = '<h1>Success, your steam profile was verified!</h1>'
  57.             output += f'<p>Discord = {user["username"]} ({user["id"]})</p>'
  58.             output += f'<p>Steam = {connection["name"]} ({connection["id"]})</p>'
  59.            
  60.             conn = await aiomysql.connect(port=3306, user='root', password='notforyou', db='discord')
  61.             async with conn.cursor() as cur:
  62.                 await cur.execute(f"INSERT INTO users(`name`,`id`,`steam`) VALUES(%s,%s,%s);", (user['username'], user['id'], connection['id']))
  63.             await conn.commit()
  64.             return(output)
  65.    
  66.     return('<h1>Error verifying steam profile, make sure you have one connected to your discord profile.</h1>')
  67. #app.run()
RAW Paste Data