Beispiel #1
0
        /// <summary>
        /// Validate a JWT
        /// </summary>
        /// <param name="formVariables"></param>
        /// <param name="secret"></param>
        /// <returns></returns>
        private LTI11Request ValidateJwt(NameValueCollection formVariables, string secret)
        {
            Exception exception = null;

            LTI11Request LTIReq = this;

            LTIReq.valid = false;

            try
            {
                buildLtiRequest(formVariables, LTIReq);
            }
            catch (Exception e)
            {
                exception = e;
            }

            return(LTIReq);
        }
Beispiel #2
0
        /// <summary>
        /// Build a validated LTI request
        /// </summary>
        /// <param name="formVariables"></param>
        /// <param name="LTIReq"></param>
        private static void buildLtiRequest(NameValueCollection formVariables, LTI11Request LTIReq)
        {
            //TODO:  validate timestamp: LTIReq.oauth_timestamp
            LTIReq.custom_canvas_css_common = formVariables[LTIRequestKeys.CustomCanvasCss] ?? "";
            LTIReq.user_id                        = formVariables[LTIRequestKeys.UserId] ?? "";
            LTIReq.roles                          = formVariables[LTIRequestKeys.Roles] ?? "";
            LTIReq.context_id                     = formVariables[LTIRequestKeys.ContextId] ?? "";
            LTIReq.context_title                  = formVariables[LTIRequestKeys.ContextTitle] ?? "";
            LTIReq.custom_canvas_api_domain       = formVariables[LTIRequestKeys.CustomCanvasApiDomain] ?? "";
            LTIReq.custom_canvas_user_id          = formVariables[LTIRequestKeys.CustomCanvasUserId] ?? "";
            LTIReq.custom_canvas_user_login_id    = formVariables[LTIRequestKeys.CustomCanvasUserLoginId] ?? "";
            LTIReq.custom_canvas_sis_course_id    = formVariables[LTIRequestKeys.CustomCanvasSisCourseId] ?? "";
            LTIReq.custom_psu_external_tool_id    = formVariables[LTIRequestKeys.CustomPsuExternalToolId] ?? "";
            LTIReq.ext_roles                      = formVariables[LTIRequestKeys.ExtRoles] ?? "";
            LTIReq.launch_presentation_return_url = formVariables[LTIRequestKeys.LaunchPresentationReturnUrl] ?? "";

            var contextLabel = (formVariables[LTIRequestKeys.ContextLabel] ?? "").Trim();

            if (contextLabel.Length > 0)
            {
                LTIReq.context_label = contextLabel;
            }

            //srg25 7/6/2015 - Adding a check to see if there is a course id or not
            var customCanvasCourseId = (formVariables[LTIRequestKeys.CustomCanvasCourseId] ?? "").Trim();

            if (customCanvasCourseId.Length > 0)
            {
                LTIReq.custom_canvas_course_id = customCanvasCourseId;
            }

            //srg25 7/6/2015 - Adding a check to see if there is an enrollment state.
            var customCanvasEncollmentState = (formVariables[LTIRequestKeys.CustomCanvasEnrollmentState] ?? "").Trim();

            if (customCanvasEncollmentState.Length > 0)
            {
                LTIReq.custom_canvas_enrollment_state = customCanvasEncollmentState;
            }

            // populate role flags
            LTIReq.isAdmin      = HasAdminRole(formVariables);
            LTIReq.isInstructor = (formVariables[LTIRequestKeys.ExtRoles] ?? "").Contains(LTIRequestKeys.ExtRoleInstructor);

            LTIReq.isStudent          = LTIReq.roles.Contains(LTIRequestKeys.RoleStudent);
            LTIReq.isCourseInstructor = LTIReq.roles.Contains(LTIRequestKeys.RoleInstructor);
            //sxn82-2016/11/29 - null check for user id.
            //if ((formVariables[LTIRequestKeys.ExtRoles] ?? "").Contains(LTIRequestKeys.ExtRoleAdministrator) && !string.IsNullOrWhiteSpace(LTIReq.custom_canvas_user_id))
            //{
            //    //srg25-2016/4/11 -  need to check to see if this person is in an allowable admin position
            //    var admRoles = CanvasAdminApiBL.ListAccountAdmins(Settings.PsuAccountId, new[] { Convert.ToInt64(LTIReq.custom_canvas_user_id) });

            //    // srg25-2016/4/11 - Get the allowable admin roles to use tool from env var value
            //    var helpdeskAdminRoles = PsuDbDal.GetEnvVar("HelpdeskAdminRoles", "1").Split(',').ToList();

            //    LTIReq.isHelpDeskAdmin = admRoles.Any(r => helpdeskAdminRoles.Contains(r.Role));

            //    // Start Revision: 2017/4/10 srg25 -- Needed another property for dev team admins
            //    var devTeamAdminRoles = PsuDbDal.GetEnvVar("DevTeamAdminRoles", "1").Split(',').ToList();

            //    LTIReq.isDevTeamAdmin = admRoles.Any(r => devTeamAdminRoles.Contains(r.Role));
            //}
            //else
            //{
            //    LTIReq.isHelpDeskAdmin = false;
            //    LTIReq.isDevTeamAdmin = false;
            //    // End Revision: 2017/4/10 srg25
            //}

            //// Get all 'Pride Admins' for this course
            //LTIReq.isGroupAdmin = false;
            //long courseid;
            //long.TryParse(LTIReq.custom_canvas_course_id, out courseid);
            //List<CanvasEnrollmentApiStruct> TAEnrollments = CanvasEnrollmentApiBL.GetCourseEnrollments(courseid, type: new string[] { "TaEnrollment" });
            //var groupAdmins = TAEnrollments.Where(r => r.Role.Equals("Pride Admin")).ToList();
            //foreach (var thisEnrollment in groupAdmins)
            //{
            //    if (thisEnrollment.User.Id.ToString() == LTIReq.custom_canvas_user_id)
            //    {
            //        LTIReq.isGroupAdmin = true;
            //    }
            //}

            //LTIReq.isCourseAdmin = false;
            //List<CanvasEnrollmentApiStruct> TeacherEnrollments = CanvasEnrollmentApiBL.GetCourseEnrollments(courseid, type: new string[] { "TeacherEnrollment" });
            //var courseAdmins = TeacherEnrollments.Where(r => r.Role.Equals("Course Admin")).ToList();
            //foreach (var thisEnrollment in courseAdmins)
            //{
            //    if (thisEnrollment.User.Id.ToString() == LTIReq.custom_canvas_user_id)
            //    {
            //        LTIReq.isCourseAdmin = true;
            //    }
            //}

            LTIReq.valid = true;
        }