cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
aakash
Community Member

LTI Variable access inside the external tool

Jump to solution

LTI variable access inside the external tool or iframe

Hi,

Here i'm created external tool manually and created custom fields. Now added code in html file for accessing user data but i'm getting cross-origin error. can anyone please explain me how can i solve this. just i want to access user data inside the external tool. I'm new to canvas any one can please explain me how to do this

thanks

1 Solution
aakash
Community Member

Hi James,

Thank you so much for your replay It's working fine now. First i trace the values using "print_r($_REQUEST)" this, I got a complete details. Now everything working fine now. 

previously i tried like this $_REQUEST['canvas_api_domain'] but that time i don't know about CUSTOM prefix. 

after adding custom prefix everything working fine. 

Thanks

View solution in original post

5 Replies
kona
Community Coach
Community Coach

 @aakash , greetings! Due to the technical nature of this question, I have shared it with the Canvas Developers group in the Community. You might consider joining this group so you have access to their resources and information. 

Kona

James
Community Champion

LTI calls make a POST call to the page with form data. You need to write a program to validate that the LTI request is valid and then process the form on the server. When you do that, you will have the values that were sent. How you do that depends on the programming language that you're using to handle the post.

POST values are sent to the server where they are handled. You're trying to use jQuery, which runs on the client side within the browser and it doesn't have access to the form submission unless the program you write on the server includes that.

For example, you could write PHP or Ruby (or other language) program that would run on the server to validate the LTI request and obtain the values of the form. Then it could generate an HTML file that would contain those in a form with hidden input values or as part of the query string.

You cannot access global variables from the parent window from within an iframe and form values from a POST are not added to what gets sent back to the browser.

aakash
Community Member

Hi James,

Thank you for the replay. Actually I'm tried different way to access LTI variables but i'm unable to access that. I Know i'm doing in wrong ways but i'm new to this.

Actually i'm creating one application and added into canvas now i want to Access user id and user name. Based on the user name and user id i'll do some Operations. Can you please check my code and just send me the correct for access user id using LTI variables. 

I wrote some Curl method also but not working can you please help.

303681_LTI issue2.png

Thanks

0 Kudos
James
Community Champion

No, I can't send you the correct code because it involves a library to process the LTI and you really need to make sure that you do that, unless you write your own library, otherwise your LTI has no security on it. Any user could fake a call and you could expose information to the wrong people.

Which library you use is going to determine where the information is stored and some provide methods for returning information. Rather than spending a bunch of time trying to make the wrong way work, learn to do it the right way. When you do it the wrong way, you're going to have trouble finding anyone who can help because you're doing it in a way completely different than what should be done and what they have done. LTI is complicated enough and security is a part of it.

I use the basic LTI library for PHP. The copy I found was old and threw lots of errors when I upgraded my PHP versions, so I hacked it extensively. I don't know where I found it exactly, but it has an Andy Smith in the license file and online searches talk about the old code that Andy did from Google Code, but it got shut down so they moved it to GitHub. There are other libraries out there.

The one I use takes the information that it receives from the POST and sticks it into an object and that has a property of info. That is an array of all the information passed, so I could access it as $LTI['info'] using the object returned from my library.

The names of them vary based on what the information is and where it comes from. The IMS LTI standard has some names, but Canvas has others and everything that you put in the Custom fields when you set it up in the LTI configuration comes through with a prefix of custom_ in the request. That means that canvas_api_domain would be custom_canvas_api_domain. In the $_REQUEST variable, it's $_REQUEST['custom_canvas_api_domain']. In my $LTI variable, I can access it as $LTI['info']['custom_canvas_api_domain'];

What I did when I was figuring things out was to use a print_r($_REQUEST) or a print_r($LTI) where $LTI is the object returned from the library that authenticates and validates the LTI call.

aakash
Community Member

Hi James,

Thank you so much for your replay It's working fine now. First i trace the values using "print_r($_REQUEST)" this, I got a complete details. Now everything working fine now. 

previously i tried like this $_REQUEST['canvas_api_domain'] but that time i don't know about CUSTOM prefix. 

after adding custom prefix everything working fine. 

Thanks