Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
AddLti10Parameters
/// <summary>
/// Add optional parameters that are specific to an LTI 1.0 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 AddLti10Parameters(Assignment assignment, OAuthParameters parameters)
{
// LTI 1.0 does not include custom parameter substitution, so the custom parameter
// values are added as-is.
if (!string.IsNullOrWhiteSpace(assignment.CustomParameters))
{
var customParams = assignment.CustomParameters.Split(new[] { ",", "\r\n", "\n" },
StringSplitOptions.RemoveEmptyEntries);
foreach (var customParam in customParams)
{
var namevalue = customParam.Split(new[] { "=" },
StringSplitOptions.RemoveEmptyEntries);
if (namevalue.Length == 2)
{
// Note that per the LTI 1.x specs, custom parameter
// names must be lowercase letters or numbers. Any other
// character is replaced with an underscore.
var name = "custom_" +
Regex.Replace(namevalue[0].ToLower(), "[^0-9a-zA-Z]", "_");
var value = namevalue[1];
parameters.AdditionalParameters.Add(name, value);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment