Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import secrets, discordoauth2, os, rblxopencloud, firebase_admin
- from dotenv import load_dotenv
- load_dotenv()
- from flask import Flask, request, redirect, jsonify
- from discordoauth2 import Client, AccessToken
- from rblxopencloud import OAuth2App
- from firebase_admin import db, credentials
- app = Flask(__name__)
- DISCORD_CLIENT_ID = os.getenv("DISCORD_CLIENT_ID")
- DISCORD_CLIENT_SECRET = os.getenv("DISCORD_CLIENT_SECRET")
- DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")
- DISCORD_REDIRECT = os.getenv("DISCORD_REDIRECT")
- ROBLOX_APP_ID = os.getenv("ROBLOX_APP_ID")
- ROBLOX_APP_SECRET = os.getenv("ROBLOX_APP_SECRET")
- ROBLOX_APP_REDIRECT = os.getenv("ROBLOX_APP_REDIRECT")
- # NOTE: this is just an example function, and may not be the same in production
- rbx_client = OAuth2App(id=ROBLOX_APP_ID, secret=ROBLOX_APP_SECRET, redirect_uri=ROBLOX_APP_REDIRECT)
- dsc_client = Client(id=DISCORD_CLIENT_ID, secret=DISCORD_CLIENT_SECRET, redirect=DISCORD_REDIRECT, bot_token=DISCORD_TOKEN)
- discord_access_cache = {}
- def fetch_roblox_id_from_discord_id(discord_id: int):
- users = db.reference("/Users")
- for info in users.get():
- if int(users.child(info).get()["discord_id"]) == int(discord_id):
- return users.child(info).get()
- return None
- @app.route("/callback/discord")
- def api_oauth_callback_discord():
- access = dsc_client.client_credentails_grant(["identify", "guilds.members.read"])
- state = secrets.token_urlsafe(16)
- discord_access_cache[state] = access.token
- print(access.token)
- return redirect(rbx_client.generate_uri(["openid", "profile"], state=state))
- @app.route("/callback/roblox")
- def api_oauth_callback_roblox():
- access = rbx_client.exchange_code(code=request.args["code"])
- robloxInfo = access.fetch_userinfo()
- cachedUsername = robloxInfo.username
- robloxId = robloxInfo.id
- discord_access = dsc_client.from_access_token(discord_access_cache[request.args.get("state")])
- discord_user = discord_access.fetch_identify()
- userInfo = fetch_roblox_id_from_discord_id(discord_user["id"])
- print(robloxId, cachedUsername, discord_user["id"])
- print(userInfo)
- if userInfo == None:
- db.reference("/Users").update({
- robloxId: {
- "cachedUsername": cachedUsername,
- "roblox_id": robloxId,
- "discord_id": discord_user["id"]
- }
- })
- return "You are verified with Orosius Authorization."
- return "You are already verified with Orosius Authorization."
- app.run(host="192.168.48.2", port=2938)
Advertisement
Add Comment
Please, Sign In to add comment