Skip to content

Commit

Permalink
#31 sending if canvas user is Proxied user or not in course payload (#32
Browse files Browse the repository at this point in the history
)

* #31 sending if canvas user is Proxied user or not in course payload
  • Loading branch information
pushyamig authored Sep 5, 2024
1 parent e8d64b3 commit d85448f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
9 changes: 5 additions & 4 deletions lti_redirect/maizey.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def get_restructured_data(self):
"course": {
"id": self.lti_custom_data["course_id"],
"name": course_title,
"sis_id": lis["course_offering_sourcedid"],
"sis_id": lis.get("course_offering_sourcedid"),
"workflow_state": self.lti_custom_data["course_status"],
"enroll_status":self.lti_custom_data["course_enroll_status"]
},
Expand All @@ -36,10 +36,11 @@ def get_restructured_data(self):
"user": {
"id": self.lti_custom_data["user_canvas_id"],
"login_id": self.lti_custom_data["login_id"],
"sis_id": lis["person_sourcedid"],
"sis_id": lis.get("person_sourcedid"),
"roles": self.lti_custom_data["roles"].split(","),
"email_address": self.lti_launch_data["email"],
"email_address": self.lti_launch_data.get("email"),
"name": self.lti_launch_data["name"],
"is_proxied_user": self.lti_custom_data["masquerade_user_canvas_id"].isdigit()
} ,
"account": {
"id": self.lti_custom_data["course_canvas_account_id"],
Expand All @@ -57,7 +58,7 @@ def send_to_maizey(self):
try:
course_jwt = jwt.encode(self.get_restructured_data(), self.maizey_jwt_secret, algorithm='HS256')
maizey_url = f"{self.lti_custom_data['redirect_url']}t2/canvaslink?token={course_jwt}"
logger.info(f"Maizey with course JWT URL: {maizey_url}")
logger.debug(f"Maizey with course JWT URL: {maizey_url}")
except (InvalidKeyError,Exception) as e:
logger.error(f"Error encoding course data to JWT: {e}")
return maizey_url
8 changes: 4 additions & 4 deletions lti_redirect/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def validate_custom_lti_launch_data(lti_launch):
"roles", "term_id", "login_id", "term_end", "course_id", "term_name", "canvas_url",
"term_start", "redirect_url", "course_status", "user_canvas_id",
"course_account_name", "course_enroll_status", "course_sis_account_id",
"course_canvas_account_id"]
"course_canvas_account_id", 'masquerade_user_canvas_id' ]
main_key = "https://purl.imsglobal.org/spec/lti/claim/custom"
if main_key not in lti_launch:
logger.error(f"LTI custom '{main_key}' variables are not configured")
Expand All @@ -38,9 +38,9 @@ def validate_custom_lti_launch_data(lti_launch):

def login_user_from_lti(request, launch_data):
try:
first_name = launch_data['given_name']
last_name = launch_data['family_name']
email = launch_data['email']
first_name = launch_data.get('given_name')
last_name = launch_data.get('family_name')
email = launch_data.get('email')
username = launch_data['https://purl.imsglobal.org/spec/lti/claim/custom']['login_id']
logger.info(f'the user {first_name} {last_name} {email} {username} launch the tool')
user_obj = User.objects.get(username=username)
Expand Down
5 changes: 3 additions & 2 deletions setup/lti-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@
"term_name": "$Canvas.term.name",
"canvas_url": "$Canvas.api.baseUrl",
"term_start": "$Canvas.term.startAt",
"redirect_url": "https://dev2.dev.umgpt.umich.edu/",
"redirect_url": "https://main.dev.umgpt.umich.edu/",
"course_status": "$Canvas.course.workflowState",
"user_canvas_id": "$Canvas.user.id",
"course_account_name": "$Canvas.account.name",
"course_enroll_status": "$Canvas.enrollment.enrollmentState",
"course_sis_account_id": "$Canvas.course.sisSourceId",
"course_canvas_account_id": "$Canvas.account.id"
"course_canvas_account_id": "$Canvas.account.id",
"masquerade_user_canvas_id": "$Canvas.masqueradingUser.id"
},
"public_jwk_url": "https://{app-hostname}/.well-known/jwks.json",
"target_link_uri": "https://{app-hostname}/ltilaunch",
Expand Down

0 comments on commit d85448f

Please sign in to comment.