mirror of
https://github.com/etnguyen03/tjdests.git
synced 2025-04-28 12:49:49 -04:00
41 lines
1.4 KiB
Python
41 lines
1.4 KiB
Python
from django.conf import settings
|
|
from social_core.backends.oauth import BaseOAuth2
|
|
|
|
|
|
class IonOauth2(BaseOAuth2):
|
|
name = "ion"
|
|
AUTHORIZATION_URL = "https://ion.tjhsst.edu/oauth/authorize"
|
|
ACCESS_TOKEN_URL = "https://ion.tjhsst.edu/oauth/token"
|
|
ACCESS_TOKEN_METHOD = "POST"
|
|
EXTRA_DATA = [("refresh_token", "refresh_token", True),
|
|
("expires_in", "expires")]
|
|
|
|
def get_scope(self):
|
|
return ["read"]
|
|
|
|
def get_user_details(self, response):
|
|
profile = self.get_json(
|
|
"https://ion.tjhsst.edu/api/profile",
|
|
params={"access_token": response["access_token"]},
|
|
)
|
|
# fields used to populate/update User model
|
|
|
|
if not profile["graduation_year"]:
|
|
profile["graduation_year"] = 0
|
|
|
|
return {
|
|
"id": profile["id"],
|
|
"username": profile["ion_username"],
|
|
"first_name": profile["first_name"],
|
|
"last_name": profile["last_name"],
|
|
"full_name": profile["full_name"],
|
|
"email": profile["tj_email"],
|
|
"is_student": profile["is_student"],
|
|
"is_teacher": profile["is_teacher"],
|
|
"graduation_year": profile["graduation_year"],
|
|
"is_senior": int(profile["graduation_year"]) == settings.SENIOR_GRAD_YEAR,
|
|
}
|
|
|
|
def get_user_id(self, details, response):
|
|
return details["id"]
|