mirror of
https://github.com/Rushilwiz/SkoolOS.git
synced 2025-04-28 15:59:55 -04:00
working
This commit is contained in:
parent
24bbe6f466
commit
3b3d378f7f
|
@ -1,7 +1,17 @@
|
|||
import sys
|
||||
import click
|
||||
from urllib.parse import urlparse
|
||||
|
||||
import requests
|
||||
from requests_oauthlib import OAuth2Session
|
||||
from selenium import webdriver;
|
||||
import os.path
|
||||
import time
|
||||
|
||||
client_id = r'QeZPBSKqdvWFfBv1VYTSv9iFGz5T9pVJtNUjbEr6'
|
||||
client_secret = r'0Wl3hAIGY9SvYOqTOLUiLNYa4OlCgZYdno9ZbcgCT7RGQ8x2f1l2HzZHsQ7ijC74A0mrOhhCVeZugqAmOADHIv5fHxaa7GqFNtQr11HX9ySTw3DscKsphCVi5P71mlGY'
|
||||
redirect_uri = 'http://localhost:8000/'
|
||||
token_url = 'https://ion.tjhsst.edu/oauth/token/'
|
||||
scope=["read"]
|
||||
|
||||
|
||||
def main():
|
||||
|
@ -16,14 +26,36 @@ def main():
|
|||
if not os.path.exists(".profile"):
|
||||
authenticate()
|
||||
else:
|
||||
print("welcome back")
|
||||
print(open(".profile", "r").read())
|
||||
|
||||
|
||||
|
||||
def authenticate():
|
||||
file = open(".profile", "w")
|
||||
file.write("Your Username")
|
||||
file.close()
|
||||
oauth = OAuth2Session(client_id=client_id, redirect_uri=redirect_uri, scope=scope)
|
||||
authorization_url, state = oauth.authorization_url("https://ion.tjhsst.edu/oauth/authorize/")
|
||||
browser = webdriver.Chrome()
|
||||
browser.get(authorization_url)
|
||||
|
||||
while "http://localhost:8000/?code" not in browser.current_url:
|
||||
time.sleep(0.25)
|
||||
|
||||
code = urlparse(browser.current_url).query[5:]
|
||||
browser.quit()
|
||||
|
||||
payload = {'grant_type': 'authorization_code', 'code': code, 'redirect_uri': redirect_uri, 'client_id': client_id,
|
||||
'client_secret': client_secret, 'csrfmiddlewaretoken': state}
|
||||
token = requests.post("https://ion.tjhsst.edu/oauth/token/", data=payload).json()
|
||||
print(token)
|
||||
# headers = {'Authorization': f"Bearer {token['access_token']}"}
|
||||
#
|
||||
# # And finally get the user's profile!
|
||||
# profile = requests.get("https://ion.tjhsst.edu/api/profile", headers=headers).json()
|
||||
# username = profile['ion_username']
|
||||
# email = profile['tj_email']
|
||||
# first_name = profile['first_name']
|
||||
# last_name = profile['last_name']
|
||||
|
||||
#print(profile)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Reference in New Issue
Block a user