wow-api-characterinfo/oauth-test.py

29 lines
1008 B
Python
Raw Normal View History

2024-12-24 09:49:14 -07:00
import requests
from http.server import *
import urllib.parse
import webbrowser
CLIENTID = "a79bae348867427690ca6df9903e4af0"
AUTH_URL = "https://oauth.battle.net/authorize"
# replace with your own http handlers
def wait_for_request(server_class=HTTPServer,
handler_class=BaseHTTPRequestHandler):
server_address = ('', 5635)
httpd = server_class(server_address, handler_class)
return httpd.handle_request()
def authenticate():
scope = "openid"
redirect_uri = 'http://localhost:5635/login_success'
params = {'client_id': CLIENTID, 'scope': scope, 'response_type': 'code',
'state': "AbCdEfG", 'redirect_uri': redirect_uri}
url = "{}?{}".format(AUTH_URL, urllib.parse.urlencode(params))
webbrowser.open(url)
response = wait_for_request()
print(response)
authenticate()
# webbrowser.open_new_tab("https://oauth.battle.net/authorize?response_type=code&scope=openid&state=AbCdEfG&redirect_uri=http://localhost&client_id=" + CLIENTID)