2024-12-24 14:18:55 -07:00
|
|
|
import http.server
|
2024-12-24 13:41:43 -07:00
|
|
|
from oauthlib.oauth2 import WebApplicationClient
|
2024-12-24 14:18:55 -07:00
|
|
|
import webbrowser
|
|
|
|
import re
|
|
|
|
import requests
|
2024-12-24 13:41:43 -07:00
|
|
|
|
|
|
|
|
2024-12-24 14:18:55 -07:00
|
|
|
class SavingRequestHandler(http.server.SimpleHTTPRequestHandler):
|
2024-12-24 13:41:43 -07:00
|
|
|
def do_GET(self):
|
2024-12-24 14:18:55 -07:00
|
|
|
SavingRequestHandler.response_path = self.path
|
2024-12-24 09:49:14 -07:00
|
|
|
|
|
|
|
|
2024-12-24 14:18:55 -07:00
|
|
|
def wait_for_request(server_class=http.server.HTTPServer,
|
|
|
|
handler_class=SavingRequestHandler):
|
2024-12-24 09:49:14 -07:00
|
|
|
server_address = ('', 5635)
|
|
|
|
httpd = server_class(server_address, handler_class)
|
|
|
|
return httpd.handle_request()
|
|
|
|
|
2024-12-24 13:41:43 -07:00
|
|
|
|
2024-12-24 09:49:14 -07:00
|
|
|
def authenticate():
|
2024-12-24 13:41:43 -07:00
|
|
|
CLIENT_ID = "a79bae348867427690ca6df9903e4af0"
|
|
|
|
AUTH_URL = "https://oauth.battle.net/authorize"
|
|
|
|
|
|
|
|
client = WebApplicationClient(CLIENT_ID)
|
|
|
|
|
|
|
|
url = client.prepare_request_uri(
|
|
|
|
AUTH_URL,
|
|
|
|
redirect_uri = 'http://localhost:5635/login_success',
|
|
|
|
scope = ['openid'],
|
|
|
|
state = 'AbCdEfG'
|
|
|
|
)
|
2024-12-24 09:49:14 -07:00
|
|
|
webbrowser.open(url)
|
2024-12-24 13:41:43 -07:00
|
|
|
wait_for_request()
|
2024-12-24 09:49:14 -07:00
|
|
|
|
|
|
|
authenticate()
|
2024-12-24 14:18:55 -07:00
|
|
|
response_code = re.search('code=(.*)&state=', SavingRequestHandler.response_path).group(1)
|
|
|
|
print("this is the way ->", response_code)
|