Add VK callback auth support and admin demotion
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import json
|
||||
import threading
|
||||
from urllib.parse import urlparse, parse_qs, unquote
|
||||
@@ -8,6 +7,13 @@ from urllib.parse import urlparse, parse_qs, unquote
|
||||
import webview
|
||||
|
||||
|
||||
AUTH_USER_AGENT = (
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
|
||||
"AppleWebKit/537.36 (KHTML, like Gecko) "
|
||||
"Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0"
|
||||
)
|
||||
|
||||
|
||||
def extract_token(url_string):
|
||||
token = None
|
||||
expires_in = 3600
|
||||
@@ -50,28 +56,59 @@ def extract_token(url_string):
|
||||
|
||||
|
||||
def main_auth(auth_url, output_path):
|
||||
stop_polling = threading.Event()
|
||||
polling_started = threading.Event()
|
||||
|
||||
def poll_url():
|
||||
try:
|
||||
url = window.get_current_url()
|
||||
except Exception:
|
||||
url = None
|
||||
if url:
|
||||
while not stop_polling.wait(0.75):
|
||||
try:
|
||||
url = window.get_current_url()
|
||||
except Exception:
|
||||
continue
|
||||
if not url:
|
||||
continue
|
||||
|
||||
token, expires_in = extract_token(url)
|
||||
if token:
|
||||
data = {"token": token, "expires_in": expires_in}
|
||||
with open(output_path, "w", encoding="utf-8") as f:
|
||||
json.dump(data, f)
|
||||
if not token:
|
||||
continue
|
||||
|
||||
stop_polling.set()
|
||||
data = {"token": token, "expires_in": expires_in}
|
||||
with open(output_path, "w", encoding="utf-8") as f:
|
||||
json.dump(data, f)
|
||||
try:
|
||||
window.destroy()
|
||||
return
|
||||
threading.Timer(0.5, poll_url).start()
|
||||
except Exception:
|
||||
pass
|
||||
return
|
||||
|
||||
def start_polling():
|
||||
if polling_started.is_set():
|
||||
return
|
||||
polling_started.set()
|
||||
thread = threading.Thread(target=poll_url, name="vk-auth-url-poller", daemon=True)
|
||||
thread.start()
|
||||
|
||||
def on_loaded():
|
||||
threading.Timer(0.5, poll_url).start()
|
||||
start_polling()
|
||||
|
||||
def on_closed():
|
||||
stop_polling.set()
|
||||
|
||||
window = webview.create_window("VK Авторизация", auth_url)
|
||||
window.events.loaded += on_loaded
|
||||
storage_path = os.path.join(os.path.dirname(output_path), "webview_profile")
|
||||
webview.start(private_mode=False, storage_path=storage_path)
|
||||
try:
|
||||
window.events.closed += on_closed
|
||||
except Exception:
|
||||
pass
|
||||
webview.start(
|
||||
start_polling,
|
||||
gui="edgechromium" if os.name == "nt" else None,
|
||||
private_mode=True,
|
||||
storage_path=None,
|
||||
user_agent=AUTH_USER_AGENT,
|
||||
)
|
||||
stop_polling.set()
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
Reference in New Issue
Block a user