Documentation ¶
Overview ¶
Implementation of LTI 1.0 Protocol in Go.
Currently there are a few major missing features such as the implementation of Tool Consumer, common cartridge parsing, proper nonce and timestamp verification.
Tool Provider Usage ¶
Tool Provider wraps a http.Request and provides easy access to LTI headers, Validation of LTI requests and creation of return URLS.
LTI headers are deserialized into a LTIStdHeaders struct which can be accessed from the LTIHeaders attribute of an LTIToolProvider.
func Handler(w http.ResponseWriter, r *http.Request) { // Create a new LTIToolProvider ltiRequest, err := lti.NewLTIToolProvider(r) // Validate LTI request valid, err := ltiRequest.ValidateRequest(secretKey, false, false) if valid == true { // Access some LTI Header fmt.Println(ltiRequest.LTIHeaders.LISPersonFamilyName) } else { // Redirect to return URL returnUrl, _ = ltiRequest.CreateReturnURL() http.Redirect(w, r, returnUrl.String(), http.StatusMovedPermanently) } }
Index ¶
- Constants
- Variables
- type LTIStdHeaders
- type LTIStdResponse
- type LTIToolConsumer
- type LTIToolProvider
- func (tp *LTIToolProvider) CreateReturnURL() (*url.URL, error)
- func (tp *LTIToolProvider) SetProxyPathPrefix(proxyPath string)
- func (tp *LTIToolProvider) SetProxyScheme(scheme string)
- func (tp *LTIToolProvider) ValidateRequest(consumerSecret string, checkTimestamp, checkNonce bool, forceTLS bool, ...) (bool, error)
Constants ¶
const ( ContextID = "context_id" ContextLabel = "context_label" ContextTitle = "context_title" ContextType = "context_type" LaunchPresHeight = "launch_presentation_height" LaunchPresLocale = "launch_presentation_locale" LaunchPresTarget = "launch_presentation_document_target" LaunchPresReturnURL = "launch_presentation_return_url" LaunchPresWidth = "launch_presentation_width" LISCourseOfferingSID = "lis_course_offering_sourcedid" LISCourseSectionSID = "lis_course_section_sourcedid" LISPersonFamilyName = "lis_person_name_family" LISPersonFullName = "lis_person_name_full" LISPersonGivenName = "lis_person_name_given" LISPersonPrimaryEmail = "lis_person_contact_email_primary" LISPersonSID = "lis_person_sourcedid" LISResultSID = "lis_result_souredid" LTIMessageType = "lti_message_type" LTIVersion = "lti_version" OAuthCallback = "oauth_callback" OAuthConsumerKey = "oauth_consumer_key" OAuthNonce = "oauth_nonce" OAuthSignature = "oauth_signature" OAuthSignatureMethod = "oauth_signature_method" OAuthTimestamp = "oauth_timestamp" OAuthVersion = "oauth_version" ResourceLinkID = "resource_link_id" ResourceLinkTitle = "resource_link_title" ResourceLinkDesc = "resource_link_description" Roles = "roles" ToolConsumerInstGUID = "tool_consumer_instance_guid" ToolConsumerInstName = "tool_consumer_instance_name" ToolConsumerInstDesc = "tool_consumer_instance_description" ToolConsumerInstURL = "tool_consumer_instance_url" ToolConsumerInstContactEmail = "tool_consumer_instance_contact_email" UserId = "user_id" UserImage = "user_image" )
Variables ¶
var ( // Resource Link ID errors ErrLogUnknownResourceLinkId = errors.New(errLogBase + "Provided Resource Link ID does not have an associated resource.") )
Exported errors
var OAuthTimestampValidationRange time.Duration = time.Minute * 10
Functions ¶
This section is empty.
Types ¶
type LTIStdHeaders ¶
type LTIStdHeaders struct { ContextID string `json:"context_id" url:"context_id,omitempty"` ContextLabel string `json:"context_label" url:"context_label,omitempty"` ContextTitle string `json:"context_title" url:"context_title,omitempty"` ContextType *types.LTIContextType `json:"context_type" url:"context_type,omitempty"` LaunchPresHeight string `json:"launch_presentation_height" url:"launch_presentation_height,omitempty"` LaunchPresLocale string `json:"launch_presentation_locale" url:"launch_presentation_locale,omitempty"` LaunchPresTarget string `json:"launch_presentation_document_target" url:"launch_presentation_document_target,omitempty"` LaunchPresReturnURL string `json:"launch_presentation_return_url" url:"launch_presentation_return_url,omitempty"` LaunchPresWidth string `json:"launch_presentation_width" url:"launch_presentation_width,omitempty"` LISCourseOfferingSID string `json:"lis_course_offering_sourcedid" url:"lis_course_offering_sourcedid,omitempty"` LISCourseSectionSID string `json:"lis_course_section_sourcedid" url:"lis_course_section_sourcedid,omitempty"` LISPersonFamilyName string `json:"lis_person_name_family" url:"lis_person_name_family,omitempty"` LISPersonFullName string `json:"lis_person_name_full" url:"lis_person_name_full,omitempty"` LISPersonGivenName string `json:"lis_person_name_given" url:",omitempty"` LISPersonPrimaryEmail string `json:"lis_person_contact_email_primary" url:"lis_person_contact_email_primary,omitempty"` LISPersonSID string `json:"lis_person_sourcedid" url:"lis_person_sourcedid,omitempty"` LISResultSID string `json:"lis_result_souredid" url:"lis_result_souredid,omitempty"` LTIMessageType types.LTIMessage `json:"lti_message_type" url:"lti_message_type,omitempty"` LTIVersion types.LTIVersion `json:"lti_version" url:"lti_version,omitempty"` OAuthCallback string `json:"oauth_callback" url:"oauth_callback,omitempty"` OAuthConsumerKey string `json:"oauth_consumer_key" url:"oauth_consumer_key,omitempty"` OAuthNonce string `json:"oauth_nonce" url:"oauth_nonce,omitempty"` OAuthSignature string `json:"oauth_signature" url:"oauth_signature,omitempty"` OAuthSignatureMethod string `json:"oauth_signature_method" url:"oauth_signature_method,omitempty"` OAuthTimestamp int `json:"oauth_timestamp" url:"oauth_timestamp,omitempty"` OAuthVersion string `json:"oauth_version" url:"oauth_version,omitempty"` ResourceLinkID string `json:"resource_link_id" url:"resource_link_id,omitempty"` ResourceLinkTitle string `json:"resource_link_title" url:"resource_link_title,omitempty"` ResourceLinkDesc string `json:"resource_link_description" url:"resource_link_description,omitempty"` Roles *types.LTIRoles `json:"roles" url:"roles,omitempty"` ToolConsumerInstGUID string `json:"tool_consumer_instance_guid" url:"tool_consumer_instance_guid,omitempty"` ToolConsumerInstName string `json:"tool_consumer_instance_name" url:"tool_consumer_instance_name,omitempty"` ToolConsumerInstDesc string `json:"tool_consumer_instance_description" url:"tool_consumer_instance_description,omitempty"` ToolConsumerInstURL string `json:"tool_consumer_instance_url" url:"tool_consumer_instance_url,omitempty"` ToolConsumerInstContactEmail string `json:"tool_consumer_instance_contact_email" url:"tool_consumer_instance_contact_email,omitempty"` UserId string `json:"user_id" schema:"user_id" url:"user_id,omitempty"` UserImage string `json:"user_image" schema:"user_image" url:"user_image,omitempty"` }
func ParseXMLEncodedFile ¶
func ParseXMLEncodedFile(filename string) (*LTIStdHeaders, error)
**Not implemented**
type LTIStdResponse ¶
type LTIStdResponse struct { LTIMessage string `url:"lti_msg,omitempty"` LTIErrorMessage string `url:"lti_errormsg,omitempty"` LTILog string `url:"lti_log,omitempty"` LTIErrorLog string `url:"lti_errorlog,omitempty"` StatusCode int `url:"-"` }
LTIStdResponse provides ability to serialize LTI response messages per LTI 1.0 spec.
func NewLTIErrorResponse ¶
func NewLTIErrorResponse(errMsg, logMsg string, statusCode int) *LTIStdResponse
Create a new LTI response with provided user error message, error log message and error status code.
func NewLTIStdResponse ¶
func NewLTIStdResponse(respMsg, logMsg string, statusCode int) *LTIStdResponse
Create a new LTI response with provided user message, log message and status code.
func (*LTIStdResponse) Serialize ¶
func (l *LTIStdResponse) Serialize() (string, error)
Serialize LTI response fields into encoded URL query string.
type LTIToolConsumer ¶
type LTIToolConsumer struct {
LTIHeaders LTIStdHeaders
}
Tool consumer is not yet implemnted.
func (*LTIToolConsumer) SendLTIReqeust ¶
func (c *LTIToolConsumer) SendLTIReqeust(l *LTIStdHeaders) (*http.Response, error)
**Not implemented**
type LTIToolProvider ¶
type LTIToolProvider struct { LTIHeaders *LTIStdHeaders LTIResponse *LTIStdResponse // contains filtered or unexported fields }
Tool provider wraps a provided http.Request, parses the LTI headers and allows for access to standard LTI Header fields as well as validation of LTI request.
func NewLTIToolProvider ¶
func NewLTIToolProvider(r *http.Request) (*LTIToolProvider, error)
Create a new LTIToolProvide and set the LTIHeaders attribute to the parsed http.Request payload. Accepts URL encoded forms per LTI 1.0 spec and additionally supports also JSON payloads.
func (*LTIToolProvider) CreateReturnURL ¶
func (tp *LTIToolProvider) CreateReturnURL() (*url.URL, error)
If the LTI request provided a return URL, serialize the LTIResponse and create a return URL from it.
func (*LTIToolProvider) SetProxyPathPrefix ¶
func (tp *LTIToolProvider) SetProxyPathPrefix(proxyPath string)
IF a request is being proxied passed, the original request host information is overwritten by the proxying host. Use this to correctly set the desired host.
TODO remove this, pull proxy path from headers
func (*LTIToolProvider) SetProxyScheme ¶
func (tp *LTIToolProvider) SetProxyScheme(scheme string)
func (*LTIToolProvider) ValidateRequest ¶
func (tp *LTIToolProvider) ValidateRequest(consumerSecret string, checkTimestamp, checkNonce bool, forceTLS bool, transformPath func(string) string) (bool, error)
Validate that the LTI request was signed with the provided consumer secret.
TODO Implement nonce checking and better timestamp checking.