Merge branch 'master' into development

This commit is contained in:
Rushil Umaretiya 2020-06-10 01:52:46 -04:00
commit 9a88dd0059
3 changed files with 25 additions and 14 deletions

1
.gitignore vendored
View File

@ -253,3 +253,4 @@ GitHub.sublime-settings
!.vscode/launch.json !.vscode/launch.json
!.vscode/extensions.json !.vscode/extensions.json
.history .history

View File

@ -14,7 +14,7 @@
</head> </head>
<body> <body>
<div class="d-flex align-items-center justify-content-center" style="height: 100vh"> <div class="d-flex align-items-center justify-content-center" style="height: 100vh">
<a href="https://ion.tjhsst.edu/oauth/authorize/?response_type=code&client_id=QeZPBSKqdvWFfBv1VYTSv9iFGz5T9pVJtNUjbEr6&redirect_uri=http%3A%2F%2Flocalhost%3A8000%2F&scope=read&state=QzCUoJEflSWlZe2v7Y3IQEXJFWKIOA" title="Ion" class="border border-dark p-3 btn btn-lg mx-auto" style="box-shadow: 5px 10px;"> <a href="https://ion.tjhsst.edu/oauth/authorize/?response_type=code&client_id=QeZPBSKqdvWFfBv1VYTSv9iFGz5T9pVJtNUjbEr6&redirect_uri=http%3A%2F%2Flocalhost%3A8000%2F&scope=read&state=w4hxAszhLTubmyrMqEbaJO6qAM4wCJ" title="Ion" class="border border-dark p-3 btn btn-lg mx-auto" style="box-shadow: 5px 10px;">
<img src="https://ion.tjhsst.edu/static/img/favicon.png"> <img src="https://ion.tjhsst.edu/static/img/favicon.png">
Sign in with Ion Sign in with Ion
</a> </a>

View File

@ -8,7 +8,7 @@ import os.path
import time import time
import http.server import http.server
import socketserver import socketserver
import threading from threading import Thread
from werkzeug.urls import url_decode from werkzeug.urls import url_decode
client_id = r'QeZPBSKqdvWFfBv1VYTSv9iFGz5T9pVJtNUjbEr6' client_id = r'QeZPBSKqdvWFfBv1VYTSv9iFGz5T9pVJtNUjbEr6'
@ -29,6 +29,7 @@ def main():
if not os.path.exists(".profile"): if not os.path.exists(".profile"):
authenticate() authenticate()
print(open(".profile", "r").read())
else: else:
print(open(".profile", "r").read()) print(open(".profile", "r").read())
@ -45,19 +46,22 @@ def authenticate():
if os.path.exists("index.html"): if os.path.exists("index.html"):
os.remove("index.html") os.remove("index.html")
template = open("template.html", "rt") template = open("template.html", "r")
index = open("index.html", "wt") index = open("index.html", "w")
for line in template: for line in template:
index.write(line.replace('AUTH_URL', authorization_url)) index.write(line.replace('AUTH_URL', authorization_url))
template.close() template.close()
index.close() index.close()
threading.Thread(target=create_server).start() # server = Thread(target=create_server)
# server.daemon = True
# server.start()
browser = webdriver.Chrome() browser = webdriver.Chrome()
browser.get("localhost:8000/") browser.get("localhost:8000/")
while "http://localhost:8000/?code" not in browser.current_url: while "http://localhost:8000/?code" not in browser.current_url:
http.server.
time.sleep(0.25) time.sleep(0.25)
url = browser.current_url url = browser.current_url
@ -75,16 +79,22 @@ def authenticate():
'client_secret': client_secret, 'csrfmiddlewaretoken': state} 'client_secret': client_secret, 'csrfmiddlewaretoken': state}
token = requests.post("https://ion.tjhsst.edu/oauth/token/", data=payload).json() token = requests.post("https://ion.tjhsst.edu/oauth/token/", data=payload).json()
print(token) print(token)
# headers = {'Authorization': f"Bearer {token['access_token']}"} headers = {'Authorization': f"Bearer {token['access_token']}"}
#
# # And finally get the user's profile! # And finally get the user's profile!
# profile = requests.get("https://ion.tjhsst.edu/api/profile", headers=headers).json() profile = requests.get("https://ion.tjhsst.edu/api/profile", headers=headers).json()
# username = profile['ion_username'] print(profile)
# email = profile['tj_email'] username = profile['ion_username']
# first_name = profile['first_name'] email = profile['tj_email']
# last_name = profile['last_name'] first_name = profile['first_name']
last_name = profile['last_name']
profileFile = open(".profile", "w")
profileFile.write(profile)
profileFile.close()
# server.stop
# print(profile)
def create_server(): def create_server():
port = 8000 port = 8000