LTI13
class LTI13
This is a general purpose LTI 1.3 class with no Tsugi-specific dependencies.
https://www.imsglobal.org/spec/lti/v1p3/
Constants
VERSION_CLAIM |
|
MESSAGE_TYPE_CLAIM |
|
MESSAGE_TYPE_RESOURCE |
|
MESSAGE_TYPE_DEEPLINK |
|
MESSAGE_TYPE_CONTENT_REVIEW |
|
MESSAGE_TYPE_PRIVACY |
|
RESOURCE_LINK_CLAIM |
|
CONTEXT_ID_CLAIM |
|
DEPLOYMENT_ID_CLAIM |
|
ROLES_CLAIM |
|
PRESENTATION_CLAIM |
|
DOCUMENT_TARGET |
|
DOCUMENT_TARGET_FRAME |
|
DOCUMENT_TARGET_IFRAME |
|
DOCUMENT_TARGET_WINDOW |
|
RETURN_URL |
|
LTI11_TRANSITION_CLAIM |
|
FOR_USER_CLAIM |
|
NAMESANDROLES_CLAIM |
|
ENDPOINT_CLAIM |
|
DEEPLINK_CLAIM |
|
CUSTOM_CLAIM |
|
MEDIA_TYPE_MEMBERSHIPS |
|
MEDIA_TYPE_LINEITEM |
|
MEDIA_TYPE_LINEITEMS |
|
SCORE_TYPE |
|
RESULTS_TYPE |
|
TOOL_PLATFORM_CLAIM |
|
PRODUCT_FAMILY_CODE |
|
LINEITEM_TIMESTAMP |
|
LINEITEM_SCOREGIVEN |
|
LINEITEM_SCOREMAXIMUM |
|
LINEITEM_COMMENT |
|
LINEITEM_USERID |
|
ACTIVITY_PROGRESS |
|
ACTIVITY_PROGRESS_INITIALIZED |
|
ACTIVITY_PROGRESS_STARTED |
|
ACTIVITY_PROGRESS_INPROGRESS |
|
ACTIVITY_PROGRESS_SUBMITTED |
|
ACTIVITY_PROGRESS_COMPLETED |
|
GRADING_PROGRESS |
|
GRADING_PROGRESS_FULLYGRADED |
|
GRADING_PROGRESS_PENDING |
|
GRADING_PROGRESS_PENDINGMANUAL |
|
GRADING_PROGRESS_FAILED |
|
GRADING_PROGRESS_NOTREADY |
|
Methods
Pull out the issuer_key from a JWT
Pull out the composite issuer_key from issuer and audience
Find the JWT in the request data
Parse and validate a raw JWT
Print out the contents of the JWT
Returns true if this is an LTI 1.3 message with minimum values to meet the protocol
Returns true if this is an LTI 1.3 message with minimum values to meet the protocol
Verify the Public Key for this request
Check the incoming message type
Check the incoming message version
Handle a curl that fails
Apply Jon Postel's Law as appropriate
Retrieve a grade token
Retrieve a Names and Roles Provisioning Service (NRPS) token
Retrieve a Names and Roles Provisioning Service (NRPS) token with source_dids
Retrieve a LineItems token
Send a line item result
Load the memberships and roles if we can get it from the LMS
Load our lineitems from the LMS
Load the detiail for a lineitem from the LMS
Load the results for a line item
Delete a lineitem from the LMS
Create a lineitem in the LMS
Update a lineitem in the LMS
Retrieve an access token
Extract an access token from returned data
Build up a basic JWT
Sign and encode a JWT
Build an HTML form to submit a JWT
No description
Cleanup common mess-ups in PKCS8 strings
Compute the base string for a Launch JWT
Compute the OAuth signature for an LTI 1.3 Launch JWT
Check the OAuth signature for an LTI 1.3 Launch JWT
Compute the HMAC256 of a string (part of LTI 1.1 Transition)
Extract a public key from a string containing a JSON keyset
Details
at line 84
static
extract_issuer_key(string $jwt)
Pull out the issuer_key from a JWT
at line 94
static
extract_issuer_key_string($issuer)
Pull out the composite issuer_key from issuer and audience
at line 106
static string
raw_jwt(array $request_data = false)
Find the JWT in the request data
at line 123
static mixed
parse_jwt(string $raw_jwt, boolean $required_fields = true)
Parse and validate a raw JWT
at line 153
static string
dump_jwt(object $jwt)
Print out the contents of the JWT
at line 176
static Returns
isRequestDetail(array $request_data = false)
Returns true if this is an LTI 1.3 message with minimum values to meet the protocol
at line 194
static Returns
isRequest(array $request_data = false)
Returns true if this is an LTI 1.3 message with minimum values to meet the protocol
at line 213
static mixed
verifyPublicKey(string $raw_jwt, string $public_key, string $algs = false)
Verify the Public Key for this request
at line 243
static boolean
isValidMessageType(string $lti_message_type)
Check the incoming message type
at line 255
static boolean
isValidVersion(string $lti_version)
Check the incoming message version
at line 265
static string
handle_curl_error($ch, $debug_log)
Handle a curl that fails
at line 292
static
jonPostel(object $body, array $failures)
Apply Jon Postel's Law as appropriate
Postel's Law - https://en.wikipedia.org/wiki/Robustness_principle
"TCP implementations should follow a general principle of robustness: be conservative in what you do, be liberal in what you accept from others."
By default, Jon Postel mode is off and we are stricter than we need to be. This works well because it reduces the arguments with the certification folks. But if you add:
$CFG->jon_postel = true;
Tsugi will follow Jon Postel's law.
at line 330
static mixed
getGradeToken($subject, $lti13_token_url, $lti13_privkey, $lti13_kid, $lti13_token_audience, $deployment_id, $debug_log = false)
Retrieve a grade token
at line 349
static mixed
getNRPSToken($subject, $lti13_token_url, $lti13_privkey, $lti13_kid, $lti13_token_audience, $deployment_id, $debug_log = false)
Retrieve a Names and Roles Provisioning Service (NRPS) token
at line 368
static mixed
getNRPSWithSourceDidsToken($subject, $lti13_token_url, $lti13_privkey, $lti13_kid, $lti13_token_audience, $deployment_id, $debug_log = false)
Retrieve a Names and Roles Provisioning Service (NRPS) token with source_dids
This should require both the lineitems and grade permission I think. But some clarification is needed to make sure this is done correctly.
at line 386
static mixed
getLineItemsToken($subject, $lti13_token_url, $lti13_privkey, $lti13_kid, $lti13_token_audience, $deployment_id, $debug_log = false)
Retrieve a LineItems token
at line 408
static mixed
sendLineItemResult($user_id, $grade, $scoreMaximum, $comment, $lineitem_url, $access_token, array $extra = false, array $debug_log = false)
Send a line item result
at line 496
static mixed
loadNRPS(string $membership_url, $access_token, array $debug_log = false)
Load the memberships and roles if we can get it from the LMS
at line 594
static mixed
loadLineItems($lineitems_url, $access_token, $debug_log = false)
Load our lineitems from the LMS
at line 647
static mixed
loadLineItem($lineitem_url, $access_token, $debug_log = false)
Load the detiail for a lineitem from the LMS
at line 701
static mixed
loadResults($lineitem_url, $access_token, $debug_log = false)
Load the results for a line item
at line 764
static mixed
deleteLineItem($lineitem_url, $access_token, $debug_log = false)
Delete a lineitem from the LMS
at line 830
static mixed
createLineItem($lineitems_url, $access_token, object $lineitem, $debug_log = false)
Create a lineitem in the LMS
at line 899
static mixed
updateLineItem($lineitem_url, $access_token, $lineitem, $debug_log = false)
Update a lineitem in the LMS
at line 957
static array
get_access_token($scope, $subject, $lti13_token_url, $lti13_privkey, $lti13_kid = false, $lti13_token_audience = false, $deployment_id = false, $debug_log = false)
Retrieve an access token
at line 1026
static mixed
extract_access_token(array $token_data, array $debug_log = false)
Extract an access token from returned data
at line 1056
static array
base_jwt(string $issuer, string $subject, array $debug_log = false)
Build up a basic JWT
at line 1079
static string
encode_jwt(array $jwt_claim, string $lti13_privkey, string $lti13_kid = false)
Sign and encode a JWT
at line 1105
static
build_jwt_html(string $launch_url, string $jws, boolean $dodebug = true, array $extra = false)
Build an HTML form to submit a JWT
at line 1150
static
generatePKCS8Pair($publicKey, $privateKey)
at line 1186
static string
cleanup_PKCS8(string $private_key)
Cleanup common mess-ups in PKCS8 strings
Often when public/private keys are pasted, stuff is added or lines run together or stuff is missing from the string. The PHP library is a little picky on these things so this routine just checks for common boo-boos and fixes them. As they say in Office Space, "We fixed the glitch."
at line 1239
static string
getLTI11TransitionBase(object $lj)
Compute the base string for a Launch JWT
See: https://www.imsglobal.org/spec/lti/v1p3/migr#lti-1-1-migration-claim
at line 1272
static string
signLTI11Transition(object $lj, string $secret)
Compute the OAuth signature for an LTI 1.3 Launch JWT
See: https://www.imsglobal.org/spec/lti/v1p3/migr#lti-1-1-migration-claim
at line 1296
static mixed
checkLTI11Transition(object $lj, string $key, string $secret)
Check the OAuth signature for an LTI 1.3 Launch JWT
See: https://www.imsglobal.org/spec/lti/v1p3/migr#lti-1-1-migration-claim
at line 1328
static string
compute_HMAC_SHA256(object $message, string $secret)
Compute the HMAC256 of a string (part of LTI 1.1 Transition)
See: https://www.imsglobal.org/spec/lti/v1p3/migr#lti-1-1-migration-claim
Based on: https://www.jokecamp.com/blog/examples-of-creating-base64-hashes-using-hmac-sha256-in-different-languages/#php
at line 1338
static
extractKeyFromKeySet($keyset_str, $kid)
Extract a public key from a string containing a JSON keyset