[O] Encapsulate get login code
This commit is contained in:
+23
-13
@@ -5,13 +5,12 @@ import urllib.parse
|
|||||||
import webbrowser
|
import webbrowser
|
||||||
from http.server import HTTPServer, BaseHTTPRequestHandler
|
from http.server import HTTPServer, BaseHTTPRequestHandler
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
|
from threading import Thread
|
||||||
|
|
||||||
import uvicorn
|
import uvicorn
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
from ruamel import yaml
|
from ruamel import yaml
|
||||||
|
|
||||||
app = FastAPI()
|
|
||||||
|
|
||||||
|
|
||||||
def load_config() -> dict:
|
def load_config() -> dict:
|
||||||
with open('auth_config.yml') as f:
|
with open('auth_config.yml') as f:
|
||||||
@@ -22,19 +21,23 @@ def load_config() -> dict:
|
|||||||
config = load_config()
|
config = load_config()
|
||||||
|
|
||||||
|
|
||||||
@app.get('/')
|
def get_login_code() -> str:
|
||||||
def callback(code: str):
|
app = FastAPI()
|
||||||
print('Login code received!')
|
result = {}
|
||||||
return 'Login success!'
|
|
||||||
|
|
||||||
|
@app.get('/')
|
||||||
|
def callback(code: str):
|
||||||
|
print('Login code received!')
|
||||||
|
result['code'] = code
|
||||||
|
return 'Login success!'
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
uvicorn.run(app, host="0.0.0.0", port=18275, reload=False)
|
uvicorn.run(app, host="0.0.0.0", port=18275, reload=False)
|
||||||
|
|
||||||
|
th = Thread(target=run)
|
||||||
|
th.start()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
# Open url in browser
|
||||||
_thread.start_new_thread(run, ())
|
|
||||||
|
|
||||||
url = "https://login.live.com/oauth20_authorize.srf?"
|
url = "https://login.live.com/oauth20_authorize.srf?"
|
||||||
url += urllib.parse.urlencode({
|
url += urllib.parse.urlencode({
|
||||||
'client_id': config['ClientID'],
|
'client_id': config['ClientID'],
|
||||||
@@ -43,6 +46,13 @@ if __name__ == '__main__':
|
|||||||
'scope': 'XboxLive.signin offline_access',
|
'scope': 'XboxLive.signin offline_access',
|
||||||
'state': 'NOT_NEEDED'
|
'state': 'NOT_NEEDED'
|
||||||
})
|
})
|
||||||
|
|
||||||
webbrowser.open(url)
|
webbrowser.open(url)
|
||||||
time.sleep(10000000)
|
|
||||||
|
while 'code' not in result:
|
||||||
|
time.sleep(0.01)
|
||||||
|
|
||||||
|
return result['code']
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
print(get_login_code())
|
||||||
|
|||||||
Reference in New Issue
Block a user