Created
November 4, 2012 19:49
-
-
Save andyfmiller/4013299 to your computer and use it in GitHub Desktop.
AddOptionalParameters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Add the optional parameters for an LTI 1.x request. | |
/// </summary> | |
/// <param name="assignment">The Assignment to be launched.</param> | |
/// <param name="parameters">The partially filled OAuthParameters object | |
/// that is being used to collect the data.</param> | |
private void AddOptionalParameters(Assignment assignment, OAuthParameters parameters) | |
{ | |
var user = db.Users.Find(WebSecurity.CurrentUserId); | |
// Tool Consumer: These identify this consumer to the provider. In K-12, tools | |
// such as LMS and Portal systems are typically purchased by the district and | |
// shared by multiple schools in the district. My advice is to use the district | |
// identity of the tool here (e.g. "Hillsboro School District LMS"). These | |
// parameters are recommended. | |
parameters.AdditionalParameters.Add("tool_consumer_instance_name", | |
"LTI Consumer Sample"); | |
parameters.AdditionalParameters.Add("tool_consumer_instance_guid", | |
Request.RequestContext.HttpContext.Request.ApplicationPath); | |
// Context: These next parameters further identify where the request coming from. | |
// "Context" can be thought of as the course or class. In this sample app, every | |
// user automatically has their own "class" or list of assignment. | |
var course = new Course(user); | |
parameters.AdditionalParameters.Add("context_id", course.Id); | |
parameters.AdditionalParameters.Add("context_label", course.Label); | |
parameters.AdditionalParameters.Add("context_title", course.Title); | |
parameters.AdditionalParameters.Add("context_type", course.LisType); | |
// User: These parameters identify the user and their roles within the | |
// context. These parameters are recommended. | |
parameters.AdditionalParameters.Add("user_id", User.Identity.Name); | |
parameters.AdditionalParameters.Add("roles", GetLtiRolesForUser()); | |
// Note that the potentially private information is suppressed if | |
// the user chooses to hide it. | |
if (user.SendEmail.GetValueOrDefault(true)) | |
{ | |
parameters.AdditionalParameters.Add("lis_person_contact_email_primary", | |
user.Email ?? string.Empty); | |
} | |
if (user.SendName.GetValueOrDefault(true)) | |
{ | |
parameters.AdditionalParameters.Add("lis_person_name_family", | |
user.LastName ?? string.Empty); | |
parameters.AdditionalParameters.Add("lis_person_name_given", | |
user.FirstName ?? string.Empty); | |
} | |
// You can use launch_presentation_locale to send the preferred presentation | |
// langauge, symbols, etc. I am sending the current UI culture (e.g. en-US). | |
// This parameter is recommended. | |
parameters.AdditionalParameters.Add("launch_presentation_locale", | |
CultureInfo.CurrentUICulture.Name); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment