chromium fix

This commit is contained in:
Raffu Khondaker 2020-06-12 18:42:55 -04:00
parent d8aa0c9b11
commit f91b7a31a7
7 changed files with 29 additions and 9 deletions

1
.profile Normal file
View File

@ -0,0 +1 @@
{'absences': 2, 'address': None, 'counselor': {'first_name': 'Sean', 'full_name': 'Sean Burke', 'id': 37, 'last_name': 'Burke', 'url': 'https://ion.tjhsst.edu/api/profile/37', 'user_type': 'counselor', 'username': 'SPBurke'}, 'display_name': 'Raffu Khondaker', 'emails': [], 'first_name': 'Raffu', 'full_name': 'Raffu Khondaker', 'grade': {'name': 'sophomore', 'number': 10}, 'graduation_year': 2022, 'id': 36508, 'ion_username': '2022rkhondak', 'is_announcements_admin': False, 'is_eighth_admin': False, 'is_student': True, 'is_teacher': False, 'last_name': 'Khondaker', 'middle_name': 'Al', 'nickname': '', 'phones': [], 'picture': 'https://ion.tjhsst.edu/api/profile/36508/picture', 'sex': 'Male', 'short_name': 'Raffu', 'title': None, 'tj_email': '2022rkhondak@tjhsst.edu', 'user_type': 'student', 'websites': []}

0
CLI/.profile Normal file
View File

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=5EVwgQRAWaQngvshhCbYiTwC9Rpi7N" 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=81xYFv6S9CLi7laXQ64gJWskDJUMMb" 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

@ -10,6 +10,7 @@ import http.server
import socketserver import socketserver
from threading import Thread from threading import Thread
from werkzeug.urls import url_decode from werkzeug.urls import url_decode
import pprint
client_id = r'QeZPBSKqdvWFfBv1VYTSv9iFGz5T9pVJtNUjbEr6' client_id = r'QeZPBSKqdvWFfBv1VYTSv9iFGz5T9pVJtNUjbEr6'
client_secret = r'0Wl3hAIGY9SvYOqTOLUiLNYa4OlCgZYdno9ZbcgCT7RGQ8x2f1l2HzZHsQ7ijC74A0mrOhhCVeZugqAmOADHIv5fHxaa7GqFNtQr11HX9ySTw3DscKsphCVi5P71mlGY' client_secret = r'0Wl3hAIGY9SvYOqTOLUiLNYa4OlCgZYdno9ZbcgCT7RGQ8x2f1l2HzZHsQ7ijC74A0mrOhhCVeZugqAmOADHIv5fHxaa7GqFNtQr11HX9ySTw3DscKsphCVi5P71mlGY'
@ -29,19 +30,29 @@ def main():
print("") print("")
if not os.path.exists(".profile"): if not os.path.exists(".profile"):
print(76546789876545678765)
authenticate() authenticate()
print(open(".profile", "r").read()) print(open(".profile", "r").read())
else: else:
print(open(".profile", "r").read()) print(open(".profile", "r").read())
while True: # while True:
pass # pass
def authenticate(): def authenticate():
oauth = OAuth2Session(client_id=client_id, redirect_uri=redirect_uri, scope=scope) oauth = OAuth2Session(client_id=client_id, redirect_uri=redirect_uri, scope=scope)
authorization_url, state = oauth.authorization_url("https://ion.tjhsst.edu/oauth/authorize/") authorization_url, state = oauth.authorization_url("https://ion.tjhsst.edu/oauth/authorize/")
cdir = os.getcwd()
#Linux: chromdriver-linux
#Macos: chromdriver-mac
#Windows: chromdriver.exe
path = os.path.join(cdir, "chromedriver-mac")
print(path)
browser = webdriver.Chrome(path)
browser = webdriver.Safari()
web_dir = os.path.join(os.path.dirname(__file__), 'oauth') web_dir = os.path.join(os.path.dirname(__file__), 'oauth')
os.chdir(web_dir) os.chdir(web_dir)
if os.path.exists("index.html"): if os.path.exists("index.html"):
@ -58,7 +69,6 @@ def authenticate():
server.daemon = True server.daemon = True
server.start() server.start()
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:
@ -83,18 +93,20 @@ def authenticate():
# 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()
print(profile)
pprint.pprint(profile)
username = profile['ion_username'] username = profile['ion_username']
email = profile['tj_email'] email = profile['tj_email']
first_name = profile['first_name'] first_name = profile['first_name']
last_name = profile['last_name'] last_name = profile['last_name']
os.chdir("..") os.chdir(cdir)
profileFile = open(".profile", "w") profileFile = open(".profile", "w")
profileFile.write(profile.text()) #profileFile.write(profile.text())
profileFile.write(str(profile))
profileFile.close() profileFile.close()
# sys.exit sys.exit
def create_server(): def create_server():

7
CLI/tester.py Normal file
View File

@ -0,0 +1,7 @@
import requests
import webbrowser
URL = "chrome://version"
webbrowser.open_new_tab(URL)
r = requests.get(url = URL)
print(r.json())

View File

@ -16,7 +16,7 @@ router.register(r'files', api_views.DefFilesViewSet)
# Wire up our API using automatic URL routing. # Wire up our API using automatic URL routing.
# Additionally, we include login URLs for the browsable API. # Additionally, we include login URLs for the browsable API.
urlpatterns = [ urlpatterns = [
path('', include(router.urls)), path('api/', include(router.urls)),
path('api-auth/', include('rest_framework.urls')), path('api-auth/', include('rest_framework.urls')),
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('login/', auth_views.LoginView.as_view(template_name="users/login.html"), name='login') path('login/', auth_views.LoginView.as_view(template_name="users/login.html"), name='login')

BIN
chromedriver-mac Executable file

Binary file not shown.