1EdTech / LTI-Tool-Provider-Library-PHP

Apache License 2.0
68 stars 74 forks source link

Set context setting 'context_type' if parameter was submitted through POST #11

Open junpataleta opened 8 years ago

junpataleta commented 8 years ago

The context_type setting doesn't seem to be set in anywhere in the ToolProvider class. So there's no way to fetch the context_type setting when needed.

I have provided a commit that saves this context setting in ToolProvider::authenticate(). Please feel free to pull this if it's correct.

Thanks!

spvickers commented 7 years ago

I would probably add the type as a property of Context. But do you think there is a need to store this value in the database so that it can be retrieved with the Context record, or will having it only available when messages are being processed fit your needs?

junpataleta commented 7 years ago

Thanks. I see, perhaps it makes better sense to set it as a property of Context. I will update the patch.

In Moodle though, we basically need to retrieve the context type later (e.g. in enrol_lti when building the memberships URL for the mod_lti membership service which has a URL template of /{context_type}/{context_id}/bindings/{vendor_code}/{product_code}/{tool_code}/memberships). So in our case, we need to save this in the database.

I would also like to confirm something about memberships URL in the library. I noticed that Context::getMembership() only uses the custom_context_memberships_url setting. But from the specs, this setting is only being passed by the tool consumers in LTI 1. Shouldn't this method handle things a little differently for LTI 2?

In the meantime though, what we did for LTI 2 is that we are building the memberships URL from the endpoint URL template for the memberships service that we got from the consumer profile. Then we save this built memberships URL as the context's custom_context_memberships_url setting. Please feel free to share your thoughts or if you have any ideas for a more appropriate approach.

Thanks!

Edit: Patch updated. Please have a look.

jeremeamia commented 7 years ago

Code looks good. 👍