LTI Variable Expansion

matthew_buckett
Community Contributor

I was just trying to pass the global account ID through to a LTI tool and this is documented on the list of LTI variables. I was using this custom field in the configuration of my LTI:

canvas_root_account_global_id=$Canvas.root_account.global_id

This was all working fine and my root account ID was getting expanded to it's value (eg 123400000000123). The problem however was that when parsing this value from a LTI 1.3 JWT using JavaScript, the custom claim was being sent across as a number and the JSON parser would read it as a number. Chrome's JavaScript engine however would use floating point representation (as it's so large) and so would round this number (making is useless most of the time).

The fix was to use substring variable expansion (which I couldn't find documented anywhere other than the source code, canvas-lms/variable_expander.rb at master · instructure/canvas-lms · GitHub ). To do this wrap the value to be expanded in ${..}, for example:

canvas_root_account_global_id=${Canvas.root_account.global_id}

This then causes it to be expanded to a string of "123400000000123" which JavaScript doesn't attempt to round.

You can also use this syntax to concatenate values into a single variable, for example:

my-var=${Canvas.shard.id}-${Canvas.root_account.id}

Hope this is useful to someone and maybe Instructure will update the documentation.

Labels (1)