Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- import quart
- import requests
- import aiomysql
- app = quart.Quart(__name__)
- API_ENDPOINT = 'https://discord.com/api/v6'
- CLIENT_ID = '691165150585290793'
- CLIENT_SECRET = 'notforyou'
- REDIRECT_URI = 'http://gm1003.wtf/exchange_code'
- @app.route('/discord', methods=['GET'])
- async def redirect_to_oauth():
- return quart.redirect(
- f'https://discordapp.com/oauth2/authorize?client_id={CLIENT_ID}&redirect_uri={REDIRECT_URI}&response_type=code&scope=identify%20connections'
- )
- @app.route('/exchange_code', methods=['GET'])
- async def exchange_code():
- data = {
- 'client_id': CLIENT_ID,
- 'client_secret': CLIENT_SECRET,
- 'grant_type': 'authorization_code',
- 'code': quart.request.args.get('code'),
- 'redirect_uri': REDIRECT_URI,
- 'scope': 'identify connections'
- }
- oauth = requests.post(
- f'{API_ENDPOINT}/oauth2/token',
- data=data,
- headers={
- 'Content-Type': 'application/x-www-form-urlencoded'
- }
- ).json()
- headers = {
- 'Content-Type': 'application/x-www-form-urlencoded',
- 'Authorization': f'Bearer {oauth["access_token"]}'
- }
- user = requests.get(
- f'{API_ENDPOINT}/users/@me',
- headers=headers
- ).json()
- connections = requests.get(
- f'{API_ENDPOINT}/users/@me/connections',
- headers=headers
- ).json()
- for connection in connections:
- if connection['type'] == 'steam' and connection['verified']:
- output = '<h1>Success, your steam profile was verified!</h1>'
- output += f'<p>Discord = {user["username"]} ({user["id"]})</p>'
- output += f'<p>Steam = {connection["name"]} ({connection["id"]})</p>'
- conn = await aiomysql.connect(port=3306, user='root', password='notforyou', db='discord')
- async with conn.cursor() as cur:
- await cur.execute(f"INSERT INTO users(`name`,`id`,`steam`) VALUES(%s,%s,%s);", (user['username'], user['id'], connection['id']))
- await conn.commit()
- return(output)
- return('<h1>Error verifying steam profile, make sure you have one connected to your discord profile.</h1>')
- #app.run()
RAW Paste Data