untested possible success
This commit is contained in:
parent
055b23c51a
commit
7de09b98ff
@ -1,28 +1,37 @@
|
|||||||
import requests
|
import requests
|
||||||
from http.server import *
|
from http.server import *
|
||||||
import urllib.parse
|
|
||||||
import webbrowser
|
import webbrowser
|
||||||
|
from oauthlib.oauth2 import WebApplicationClient
|
||||||
|
|
||||||
|
|
||||||
|
class SavingRequestHandler(SimpleHTTPRequestHandler):
|
||||||
|
def do_GET(self):
|
||||||
|
print(self.path)
|
||||||
|
def do_POST(self):
|
||||||
|
content_length = int(self.headers.get('Content-Length'))
|
||||||
|
print(self.rfile.read(content_length))
|
||||||
|
|
||||||
CLIENTID = "a79bae348867427690ca6df9903e4af0"
|
|
||||||
AUTH_URL = "https://oauth.battle.net/authorize"
|
|
||||||
|
|
||||||
# replace with your own http handlers
|
|
||||||
def wait_for_request(server_class=HTTPServer,
|
def wait_for_request(server_class=HTTPServer,
|
||||||
handler_class=BaseHTTPRequestHandler):
|
handler_class=SavingHTTPRequestHandler):
|
||||||
server_address = ('', 5635)
|
server_address = ('', 5635)
|
||||||
httpd = server_class(server_address, handler_class)
|
httpd = server_class(server_address, handler_class)
|
||||||
return httpd.handle_request()
|
return httpd.handle_request()
|
||||||
|
|
||||||
|
|
||||||
def authenticate():
|
def authenticate():
|
||||||
scope = "openid"
|
CLIENT_ID = "a79bae348867427690ca6df9903e4af0"
|
||||||
redirect_uri = 'http://localhost:5635/login_success'
|
AUTH_URL = "https://oauth.battle.net/authorize"
|
||||||
params = {'client_id': CLIENTID, 'scope': scope, 'response_type': 'code',
|
|
||||||
'state': "AbCdEfG", 'redirect_uri': redirect_uri}
|
client = WebApplicationClient(CLIENT_ID)
|
||||||
url = "{}?{}".format(AUTH_URL, urllib.parse.urlencode(params))
|
|
||||||
|
url = client.prepare_request_uri(
|
||||||
|
AUTH_URL,
|
||||||
|
redirect_uri = 'http://localhost:5635/login_success',
|
||||||
|
scope = ['openid'],
|
||||||
|
state = 'AbCdEfG'
|
||||||
|
)
|
||||||
webbrowser.open(url)
|
webbrowser.open(url)
|
||||||
response = wait_for_request()
|
wait_for_request()
|
||||||
print(response)
|
|
||||||
|
|
||||||
authenticate()
|
authenticate()
|
||||||
|
|
||||||
# webbrowser.open_new_tab("https://oauth.battle.net/authorize?response_type=code&scope=openid&state=AbCdEfG&redirect_uri=http://localhost&client_id=" + CLIENTID)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user