diff --git a/spfn-main.py b/spfn-main.py index 02b3e03..81a27cc 100644 --- a/spfn-main.py +++ b/spfn-main.py @@ -1,12 +1,3 @@ -#TODO: make this more modular for future use - -# TLDR FOR ANYONE READING THIS: -# THIS IS A SIMPLE API TO ACCEPT LOGIN REQUESTS -# FROM THE NN LOGIN PAGE ON THE SPLATNET RECREATION -#yes i unintentionally had caps on im sorry, but this is -# a really thrown together piece of code so whatever -# breaks will most likely be rewritten later - from flask import Flask, request, redirect import requests import base64 @@ -15,35 +6,72 @@ app = Flask(__name__) SPFN_API_URL = "https://account.spfn.net/api/v2/oauth2/generate_token" +def generate_spfn_token(encoded_creds): + headers = { + "Authorization": f"Basic {encoded_creds}", + "User-Agent": "saturday & allison should lwk kiss..." + } + + response = requests.get(SPFN_API_URL, headers=headers, timeout=10) + if not response.ok: + return None + + data = response.json() + return data.get("token") + + @app.route('/api/v2/sso/spfn/generate_token', methods=['POST']) def handle_login(): username = request.form.get('username') password = request.form.get('password') - - #fuck you login_host + + # fuck you login_host login_host = request.referrer or "/" if login_host.endswith('/'): login_host = login_host[:-1] creds = f"{username} {password}" encoded_creds = base64.b64encode(creds.encode()).decode() - headers = { - "Authorization": f"Basic {encoded_creds}", - "User-Agent": "maple if you see this its 10:27am with no sleep how do you feel about this" - } try: - response = requests.get(SPFN_API_URL, headers=headers, timeout=10) + token = generate_spfn_token(encoded_creds) + + #if onika eat burgers then does oomi appear? + if token: + print("=== TOKEN ===") + print(token) + print("=============") + + profile_headers = { + "Authorization": f"Bearer {token}", + "User-Agent": "maple still awake" + } + + profile_response = requests.get( + "https://account.spfn.net/api/v2/users/@me/profile", + headers=profile_headers, + timeout=10 + ) + + if profile_response.ok: + print("=== PROFILE ===") + print(profile_response.text) + print("===============") + else: + print("Profile request failed:", profile_response.status_code) - if response.ok: redirect_to = request.args.get('redirect', f"{login_host}/friend_list/") return redirect(redirect_to) + else: sep = "&" if "?" in login_host else "?" - return redirect(f"{login_host}/users/auth/splatfestival/{sep}error=auth&username={username}") + return redirect( + f"{login_host}/users/auth/splatfestival/{sep}error=auth&username={username}" + ) except Exception as e: return f"Proxy Error: {str(e)}", 500 + if __name__ == '__main__': - app.run(port=5000) \ No newline at end of file + app.run(port=5000)