From 3748a83587382e63a8ec88bb3da77f43dcab9644 Mon Sep 17 00:00:00 2001 From: Hykilpikonna Date: Wed, 31 Aug 2022 12:51:52 -0400 Subject: [PATCH] [+] MS login --- .gitignore | 1 + auth_config.yml | 1 + mc_auth/auth.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 3 +++ 4 files changed, 53 insertions(+) create mode 100644 auth_config.yml create mode 100644 mc_auth/auth.py create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore index 3eb56cb..b38eb25 100644 --- a/.gitignore +++ b/.gitignore @@ -150,3 +150,4 @@ cython_debug/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. .idea/ +*.iml diff --git a/auth_config.yml b/auth_config.yml new file mode 100644 index 0000000..c288675 --- /dev/null +++ b/auth_config.yml @@ -0,0 +1 @@ +ClientID: 5879b901-131e-464b-8499-140db808b27b diff --git a/mc_auth/auth.py b/mc_auth/auth.py new file mode 100644 index 0000000..67865a9 --- /dev/null +++ b/mc_auth/auth.py @@ -0,0 +1,48 @@ +import _thread +import os +import time +import urllib.parse +import webbrowser +from http.server import HTTPServer, BaseHTTPRequestHandler +from io import StringIO + +import uvicorn +from fastapi import FastAPI +from ruamel import yaml + +app = FastAPI() + + +def load_config() -> dict: + with open('auth_config.yml') as f: + yml = yaml.safe_load(f) + return yml + + +config = load_config() + + +@app.get('/') +def callback(code: str): + print('Login code received!') + return 'Login success!' + + +def run(): + uvicorn.run(app, host="0.0.0.0", port=18275, reload=False) + + +if __name__ == '__main__': + _thread.start_new_thread(run, ()) + + url = "https://login.live.com/oauth20_authorize.srf?" + url += urllib.parse.urlencode({ + 'client_id': config['ClientID'], + 'response_type': 'code', + 'redirect_uri': 'http://localhost:18275', + 'scope': 'XboxLive.signin offline_access', + 'state': 'NOT_NEEDED' + }) + + webbrowser.open(url) + time.sleep(10000000) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..52c9a50 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +fastapi +uvicorn~=0.18.3 +ruamel.yaml