LTI13
in package
This is a general purpose LTI 1.3 class with no Tsugi-specific dependencies.
https://www.imsglobal.org/spec/lti/v1p3/
Table of Contents
Constants
- ACTIVITY_PROGRESS : mixed = 'activityProgress'
- ACTIVITY_PROGRESS_COMPLETED : mixed = 'Completed'
- ACTIVITY_PROGRESS_INITIALIZED : mixed = 'Initialized'
- ACTIVITY_PROGRESS_INPROGRESS : mixed = 'InProgress'
- ACTIVITY_PROGRESS_STARTED : mixed = 'Started'
- ACTIVITY_PROGRESS_SUBMITTED : mixed = 'Submitted'
- CONTEXT_ID_CLAIM : mixed = 'https://purl.imsglobal.org/spec/lti/claim/cont...
- CUSTOM_CLAIM : mixed = 'https://purl.imsglobal.org/spec/lti/claim/custom'
- DEEPLINK_CLAIM : mixed = 'https://purl.imsglobal.org/spec/lti-dl/claim/d...
- DEPLOYMENT_ID_CLAIM : mixed = 'https://purl.imsglobal.org/spec/lti/claim/depl...
- DOCUMENT_TARGET : mixed = 'document_target'
- DOCUMENT_TARGET_FRAME : mixed = 'frame'
- DOCUMENT_TARGET_IFRAME : mixed = 'iframe'
- DOCUMENT_TARGET_WINDOW : mixed = 'window'
- ENDPOINT_CLAIM : mixed = 'https://purl.imsglobal.org/spec/lti-ags/claim/...
- ERROR_RETURN_URL : mixed = 'error_return_url'
- FOR_USER_CLAIM : mixed = 'https://purl.imsglobal.org/spec/lti/claim/for_...
- GRADING_PROGRESS : mixed = 'gradingProgress'
- GRADING_PROGRESS_FAILED : mixed = 'Failed'
- GRADING_PROGRESS_FULLYGRADED : mixed = 'FullyGraded'
- GRADING_PROGRESS_NOTREADY : mixed = 'NotReady'
- GRADING_PROGRESS_PENDING : mixed = 'Pending'
- GRADING_PROGRESS_PENDINGMANUAL : mixed = 'PendingManual'
- GROUPS_CLAIM : mixed = 'https://purl.imsglobal.org/spec/lti-gs/claim/g...
- LINEITEM_COMMENT : mixed = "comment"
- LINEITEM_SCOREGIVEN : mixed = "scoreGiven"
- LINEITEM_SCOREMAXIMUM : mixed = "scoreMaximum"
- LINEITEM_TIMESTAMP : mixed = "timestamp"
- LINEITEM_USERID : mixed = "userId"
- LTI11_TRANSITION_CLAIM : mixed = 'https://purl.imsglobal.org/spec/lti/claim/lti1p1'
- MEDIA_TYPE_GROUPS : mixed = 'application/vnd.ims.lti-gs.v1.contextgroupcont...
- MEDIA_TYPE_LINEITEM : mixed = 'application/vnd.ims.lis.v2.lineitem+json'
- MEDIA_TYPE_LINEITEMS : mixed = 'application/vnd.ims.lis.v2.lineitemcontainer+j...
- MEDIA_TYPE_MEMBERSHIPS : mixed = 'application/vnd.ims.lti-nrps.v2.membershipcont...
- MESSAGE_TYPE_CLAIM : mixed = 'https://purl.imsglobal.org/spec/lti/claim/mess...
- MESSAGE_TYPE_CONTENT_REVIEW : mixed = 'LtiSubmissionReviewRequest'
- MESSAGE_TYPE_DEEPLINK : mixed = 'LtiDeepLinkingRequest'
- MESSAGE_TYPE_PRIVACY : mixed = 'LtiDataPrivacyLaunchRequest'
- MESSAGE_TYPE_RESOURCE : mixed = 'LtiResourceLinkRequest'
- NAMESANDROLES_CLAIM : mixed = 'https://purl.imsglobal.org/spec/lti-nrps/claim...
- PNP_CLAIM : mixed = 'https://purl.imsglobal.org/spec/lti-afapnp/cla...
- PRESENTATION_CLAIM : mixed = 'https://purl.imsglobal.org/spec/lti/claim/laun...
- PRODUCT_FAMILY_CODE : mixed = "product_family_code"
- RESOURCE_LINK_CLAIM : mixed = 'https://purl.imsglobal.org/spec/lti/claim/reso...
- RESULTS_TYPE : mixed = 'application/vnd.ims.lis.v2.resultcontainer+json'
- RETURN_URL : mixed = 'return_url'
- ROLES_CLAIM : mixed = 'https://purl.imsglobal.org/spec/lti/claim/roles'
- SCORE_TYPE : mixed = 'application/vnd.ims.lis.v1.score+json'
- TOOL_PLATFORM_CLAIM : mixed = 'https://purl.imsglobal.org/spec/lti/claim/tool...
- VERSION_CLAIM : mixed = 'https://purl.imsglobal.org/spec/lti/claim/vers...
Methods
- base_jwt() : array<string|int, mixed>
- Build up a basic JWT
- build_jwt_html() : mixed
- Build an HTML form to submit a JWT
- checkLTI11Transition() : mixed
- Check the OAuth signature for an LTI 1.3 Launch JWT
- cleanup_PKCS8() : string
- Cleanup common mess-ups in PKCS8 strings
- client_id_from_aud() : string|null
- Client id from an ID token aud claim.
- compute_HMAC_SHA256() : string
- Compute the HMAC256 of a string (part of LTI 1.1 Transition)
- createLineItem() : mixed
- Create a lineitem in the LMS
- deleteLineItem() : mixed
- Delete a lineitem from the LMS
- dump_jwt() : string
- Print out the contents of the JWT
- encode_jwt() : string
- Sign and encode a JWT
- extract_access_token() : mixed
- Extract an access token from returned data
- extract_issuer_key() : mixed
- Pull out the issuer_key from a JWT
- extract_issuer_key_string() : mixed
- Pull out the composite issuer_key from issuer and audience
- extractKeyFromKeySet() : mixed
- Extract a public key from a string containing a JSON keyset.
- generatePKCS8Pair() : string|true
- Generate a PKCS8 Ppublic / private key pair
- get_access_token() : array<string|int, mixed>
- Retrieve an access token
- getGradeToken() : mixed
- Retrieve a grade token
- getGroupsToken() : mixed
- Retrieve a Course Group Service token
- getLineItemsToken() : mixed
- Retrieve a LineItems token
- getLTI11TransitionBase() : string
- Compute the base string for a Launch JWT
- getNRPSToken() : mixed
- Retrieve a Names and Roles Provisioning Service (NRPS) token
- getNRPSWithSourceDidsToken() : mixed
- Retrieve a Names and Roles Provisioning Service (NRPS) token with source_dids
- handle_curl_error() : string
- Handle a curl that fails
- isRequest() : Returns
- Returns true if this is an LTI 1.3 message with minimum values to meet the protocol
- isRequestDetail() : Returns
- Returns true if this is an LTI 1.3 message with minimum values to meet the protocol
- isValidMessageType() : bool
- Check the incoming message type
- isValidVersion() : bool
- Check the incoming message version
- jonPostel() : mixed
- Apply Jon Postel's Law as appropriate
- loadGroups() : mixed
- Load the groups if we can get them from the LMS
- loadLineItem() : mixed
- Load the detiail for a lineitem from the LMS
- loadLineItems() : mixed
- Load our lineitems from the LMS
- loadNRPS() : mixed
- Load the memberships and roles if we can get it from the LMS
- loadResults() : mixed
- Load the results for a line item
- parse_jwt() : mixed
- Parse and validate a raw JWT
- raw_jwt() : string
- Find the JWT in the request data
- sendLineItemResult() : mixed
- Send a line item result
- setUserAgentCurl() : mixed
- signLTI11Transition() : string
- Compute the OAuth signature for an LTI 1.3 Launch JWT
- updateLineItem() : mixed
- Update a lineitem in the LMS
- verifyPublicKey() : mixed
- Verify the Public Key for this request
- partialOrError() : object|string
- Keep members already loaded when a later page fails and a page cap is set.
Constants
ACTIVITY_PROGRESS
public
mixed
ACTIVITY_PROGRESS
= 'activityProgress'
ACTIVITY_PROGRESS_COMPLETED
public
mixed
ACTIVITY_PROGRESS_COMPLETED
= 'Completed'
ACTIVITY_PROGRESS_INITIALIZED
public
mixed
ACTIVITY_PROGRESS_INITIALIZED
= 'Initialized'
ACTIVITY_PROGRESS_INPROGRESS
public
mixed
ACTIVITY_PROGRESS_INPROGRESS
= 'InProgress'
ACTIVITY_PROGRESS_STARTED
public
mixed
ACTIVITY_PROGRESS_STARTED
= 'Started'
ACTIVITY_PROGRESS_SUBMITTED
public
mixed
ACTIVITY_PROGRESS_SUBMITTED
= 'Submitted'
CONTEXT_ID_CLAIM
public
mixed
CONTEXT_ID_CLAIM
= 'https://purl.imsglobal.org/spec/lti/claim/context'
CUSTOM_CLAIM
public
mixed
CUSTOM_CLAIM
= 'https://purl.imsglobal.org/spec/lti/claim/custom'
DEEPLINK_CLAIM
public
mixed
DEEPLINK_CLAIM
= 'https://purl.imsglobal.org/spec/lti-dl/claim/deep_linking_settings'
DEPLOYMENT_ID_CLAIM
public
mixed
DEPLOYMENT_ID_CLAIM
= 'https://purl.imsglobal.org/spec/lti/claim/deployment_id'
DOCUMENT_TARGET
public
mixed
DOCUMENT_TARGET
= 'document_target'
DOCUMENT_TARGET_FRAME
public
mixed
DOCUMENT_TARGET_FRAME
= 'frame'
DOCUMENT_TARGET_IFRAME
public
mixed
DOCUMENT_TARGET_IFRAME
= 'iframe'
DOCUMENT_TARGET_WINDOW
public
mixed
DOCUMENT_TARGET_WINDOW
= 'window'
ENDPOINT_CLAIM
public
mixed
ENDPOINT_CLAIM
= 'https://purl.imsglobal.org/spec/lti-ags/claim/endpoint'
ERROR_RETURN_URL
public
mixed
ERROR_RETURN_URL
= 'error_return_url'
FOR_USER_CLAIM
public
mixed
FOR_USER_CLAIM
= 'https://purl.imsglobal.org/spec/lti/claim/for_user'
GRADING_PROGRESS
public
mixed
GRADING_PROGRESS
= 'gradingProgress'
GRADING_PROGRESS_FAILED
public
mixed
GRADING_PROGRESS_FAILED
= 'Failed'
GRADING_PROGRESS_FULLYGRADED
public
mixed
GRADING_PROGRESS_FULLYGRADED
= 'FullyGraded'
GRADING_PROGRESS_NOTREADY
public
mixed
GRADING_PROGRESS_NOTREADY
= 'NotReady'
GRADING_PROGRESS_PENDING
public
mixed
GRADING_PROGRESS_PENDING
= 'Pending'
GRADING_PROGRESS_PENDINGMANUAL
public
mixed
GRADING_PROGRESS_PENDINGMANUAL
= 'PendingManual'
GROUPS_CLAIM
public
mixed
GROUPS_CLAIM
= 'https://purl.imsglobal.org/spec/lti-gs/claim/groupsservice'
LINEITEM_COMMENT
public
mixed
LINEITEM_COMMENT
= "comment"
LINEITEM_SCOREGIVEN
public
mixed
LINEITEM_SCOREGIVEN
= "scoreGiven"
LINEITEM_SCOREMAXIMUM
public
mixed
LINEITEM_SCOREMAXIMUM
= "scoreMaximum"
LINEITEM_TIMESTAMP
public
mixed
LINEITEM_TIMESTAMP
= "timestamp"
LINEITEM_USERID
public
mixed
LINEITEM_USERID
= "userId"
LTI11_TRANSITION_CLAIM
public
mixed
LTI11_TRANSITION_CLAIM
= 'https://purl.imsglobal.org/spec/lti/claim/lti1p1'
MEDIA_TYPE_GROUPS
public
mixed
MEDIA_TYPE_GROUPS
= 'application/vnd.ims.lti-gs.v1.contextgroupcontainer+json'
MEDIA_TYPE_LINEITEM
public
mixed
MEDIA_TYPE_LINEITEM
= 'application/vnd.ims.lis.v2.lineitem+json'
MEDIA_TYPE_LINEITEMS
public
mixed
MEDIA_TYPE_LINEITEMS
= 'application/vnd.ims.lis.v2.lineitemcontainer+json'
MEDIA_TYPE_MEMBERSHIPS
public
mixed
MEDIA_TYPE_MEMBERSHIPS
= 'application/vnd.ims.lti-nrps.v2.membershipcontainer+json'
MESSAGE_TYPE_CLAIM
public
mixed
MESSAGE_TYPE_CLAIM
= 'https://purl.imsglobal.org/spec/lti/claim/message_type'
MESSAGE_TYPE_CONTENT_REVIEW
public
mixed
MESSAGE_TYPE_CONTENT_REVIEW
= 'LtiSubmissionReviewRequest'
MESSAGE_TYPE_DEEPLINK
public
mixed
MESSAGE_TYPE_DEEPLINK
= 'LtiDeepLinkingRequest'
MESSAGE_TYPE_PRIVACY
public
mixed
MESSAGE_TYPE_PRIVACY
= 'LtiDataPrivacyLaunchRequest'
MESSAGE_TYPE_RESOURCE
public
mixed
MESSAGE_TYPE_RESOURCE
= 'LtiResourceLinkRequest'
NAMESANDROLES_CLAIM
public
mixed
NAMESANDROLES_CLAIM
= 'https://purl.imsglobal.org/spec/lti-nrps/claim/namesroleservice'
PNP_CLAIM
public
mixed
PNP_CLAIM
= 'https://purl.imsglobal.org/spec/lti-afapnp/claim/afapnp-endpoint-service'
PRESENTATION_CLAIM
public
mixed
PRESENTATION_CLAIM
= 'https://purl.imsglobal.org/spec/lti/claim/launch_presentation'
PRODUCT_FAMILY_CODE
public
mixed
PRODUCT_FAMILY_CODE
= "product_family_code"
RESOURCE_LINK_CLAIM
public
mixed
RESOURCE_LINK_CLAIM
= 'https://purl.imsglobal.org/spec/lti/claim/resource_link'
RESULTS_TYPE
public
mixed
RESULTS_TYPE
= 'application/vnd.ims.lis.v2.resultcontainer+json'
RETURN_URL
public
mixed
RETURN_URL
= 'return_url'
ROLES_CLAIM
public
mixed
ROLES_CLAIM
= 'https://purl.imsglobal.org/spec/lti/claim/roles'
SCORE_TYPE
public
mixed
SCORE_TYPE
= 'application/vnd.ims.lis.v1.score+json'
TOOL_PLATFORM_CLAIM
public
mixed
TOOL_PLATFORM_CLAIM
= 'https://purl.imsglobal.org/spec/lti/claim/tool_platform'
VERSION_CLAIM
public
mixed
VERSION_CLAIM
= 'https://purl.imsglobal.org/spec/lti/claim/version'
Methods
base_jwt()
Build up a basic JWT
public
static base_jwt(string $issuer, string $subject[, array<string|int, mixed> &$debug_log = false ]) : array<string|int, mixed>
Parameters
- $issuer : string
-
Who we are
- $subject : string
-
Who we are
- $debug_log : array<string|int, mixed> = false
-
An optional array passed by reference. Actions taken will be logged into this array.
Return values
array<string|int, mixed> —The basic fields of the JWT are populated
build_jwt_html()
Build an HTML form to submit a JWT
public
static build_jwt_html(string $launch_url, string $jws[, mixed $dodebug = true ][, array<string|int, mixed> $extra = false ]) : mixed
Parameters
- $launch_url : string
-
The URL to send the JWT
- $jws : string
-
The signed JWT
- $dodebug : mixed = true
- $extra : array<string|int, mixed> = false
-
some extra/optional parameters
formattr - Additional text to include within the <form tag button - The text of the botton (ie. to allow I18N)
@return string The HTML to send to the browser
checkLTI11Transition()
Check the OAuth signature for an LTI 1.3 Launch JWT
public
static checkLTI11Transition(object $lj, string $key, string $secret) : mixed
See: https://www.imsglobal.org/spec/lti/v1p3/migr#lti-1-1-migration-claim
Parameters
- $lj : object
-
The Launch JSON Web Token with the LTI 11 transition data
- $key : string
-
The OAuth key
- $secret : string
-
The OAuth secret
Return values
mixed —true if the signature matches, false if the JWT the signature does not match, and a string with an error if the JWT data is malformed.
cleanup_PKCS8()
Cleanup common mess-ups in PKCS8 strings
public
static cleanup_PKCS8(string $private_key) : string
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."
Parameters
- $private_key : string
-
The possible ill-formatted private key
Return values
string —The hopefully better formatted private key
client_id_from_aud()
Client id from an ID token aud claim.
public
static client_id_from_aud(mixed $aud[, mixed $azp = null ]) : string|null
IMS Security Framework 1.0 allows aud to be one string or an array of strings. A string (Canvas) and a one-element array (Schoology) are the same client id. With several audiences, azp is the client id when it is one of those audiences. Otherwise there is no single client id to look up.
Parameters
- $aud : mixed
-
aud claim
- $azp : mixed = null
-
optional azp claim
Return values
string|nullcompute_HMAC_SHA256()
Compute the HMAC256 of a string (part of LTI 1.1 Transition)
public
static compute_HMAC_SHA256(object $message, string $secret) : string
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
Parameters
- $message : object
-
The message to sign
- $secret : string
-
The secret used to sign the message
Return values
string —The signed message
createLineItem()
Create a lineitem in the LMS
public
static createLineItem(mixed $lineitems_url, mixed $access_token, object $lineitem[, mixed &$debug_log = false ]) : mixed
Parameters
- $lineitems_url : mixed
-
The REST endpoint (id) for this line item
- $access_token : mixed
-
The access token for this request
- $lineitem : object
-
The fields for the new line item
$newitem = new \stdClass(); $newitem->scoreMaximum = 100; $newitem->label = 'Week 3 Feedback'; $newitem->resourceId = '2987487943'; $newitem->tag = 'optional';
- $debug_log : mixed = false
-
Returns a log of actions taken
Return values
mixed —If this works it returns an array including the new line item url. If it fails, it returns a string.
deleteLineItem()
Delete a lineitem from the LMS
public
static deleteLineItem(mixed $lineitem_url, mixed $access_token[, mixed &$debug_log = false ]) : mixed
Parameters
- $lineitem_url : mixed
-
The REST endpoint (id) for this line item
- $access_token : mixed
-
The access token for this request
- $debug_log : mixed = false
-
Returns a log of actions taken
Return values
mixed —If this works it returns true. If it fails, it returns a string.
dump_jwt()
Print out the contents of the JWT
public
static dump_jwt(mixed $jwt) : string
Parameters
- $jwt : mixed
Return values
string —The output of the JWT suitable for printing (escaping needed)
encode_jwt()
Sign and encode a JWT
public
static encode_jwt(array<string|int, mixed> $jwt_claim, string $lti13_privkey[, string $lti13_kid = false ]) : string
Parameters
- $jwt_claim : array<string|int, mixed>
-
An array of key/value pairs for the claims
- $lti13_privkey : string
-
The private key to use to sign the JWT
- $lti13_kid : string = false
-
The key id to include in the JWT (optional)
Return values
string —The signed JWT
extract_access_token()
Extract an access token from returned data
public
static extract_access_token(array<string|int, mixed> $token_data[, array<string|int, mixed> &$debug_log = false ]) : mixed
Parameters
- $token_data : array<string|int, mixed>
-
The JSON response to a token request, parsed in an array of key / value pairs.
- $debug_log : array<string|int, mixed> = false
-
An optional array passed by reference. Actions taken will be logged into this array.
Return values
mixed —This returns the token as a string if it is successful, or false
extract_issuer_key()
Pull out the issuer_key from a JWT
public
static extract_issuer_key(string $jwt) : mixed
Parameters
- $jwt : string
-
The parsed JWT
extract_issuer_key_string()
Pull out the composite issuer_key from issuer and audience
public
static extract_issuer_key_string(mixed $issuer) : mixed
Parameters
- $issuer : mixed
extractKeyFromKeySet()
Extract a public key from a string containing a JSON keyset.
public
static extractKeyFromKeySet(mixed $keyset_str, mixed $kid[, mixed $defaultAlg = 'RS256' ]) : mixed
$defaultAlg is used when a key omits alg. LTI 1.3 platform keys are RS256.
Parameters
- $keyset_str : mixed
- $kid : mixed
- $defaultAlg : mixed = 'RS256'
generatePKCS8Pair()
Generate a PKCS8 Ppublic / private key pair
public
static generatePKCS8Pair(string &$publicKey, string &$privateKey) : string|true
Parameters
- $publicKey : string
-
Returned public key
- $privateKey : string
-
Returned private key
Return values
string|true —If there was an error, we return it, on success return true
get_access_token()
Retrieve an access token
public
static get_access_token(array<string|int, mixed> $scope, string $subject, string $lti13_token_url, string $lti13_privkey[, string $lti13_kid = false ][, string $lti13_token_audience = false ][, string $deployment_id = false ][, array<string|int, mixed> &$debug_log = false ]) : array<string|int, mixed>
Parameters
- $scope : array<string|int, mixed>
-
A list of requested scopes
- $subject : string
-
Who we are (client id in OAuth)
- $lti13_token_url : string
- $lti13_privkey : string
- $lti13_kid : string = false
-
The optional kid to include in the JWT
- $lti13_token_audience : string = false
-
The optional value for token audience. If not provided, use the $lti13_token_url.
- $deployment_id : string = false
-
The optional deployment_id to include in the JWT
- $debug_log : array<string|int, mixed> = false
-
An optional array passed by reference. Actions taken will be logged into this array.
Note - the idea of lti13_token_audience came in the following PR https://github.com/IMSGlobal/lti-spec-guides/pull/11/files
Return values
array<string|int, mixed> —The retrieved and parsed JSON data. There is no validation performed, and we might have got a 403 and received no data at all.
getGradeToken()
Retrieve a grade token
public
static getGradeToken(mixed $subject, mixed $lti13_token_url, mixed $lti13_privkey, mixed $lti13_kid, mixed $lti13_token_audience, mixed $deployment_id[, array<string|int, mixed> &$debug_log = false ]) : mixed
Parameters
- $subject : mixed
- $lti13_token_url : mixed
- $lti13_privkey : mixed
- $lti13_kid : mixed
- $lti13_token_audience : mixed
- $deployment_id : mixed
- $debug_log : array<string|int, mixed> = false
-
An optional array passed by reference. Actions taken will be logged into this array.
Return values
mixed —Returns the token (string) or false on error.
getGroupsToken()
Retrieve a Course Group Service token
public
static getGroupsToken(mixed $subject, mixed $lti13_token_url, mixed $lti13_privkey, mixed $lti13_kid, mixed $lti13_token_audience, mixed $deployment_id[, array<string|int, mixed> &$debug_log = false ]) : mixed
Parameters
- $subject : mixed
- $lti13_token_url : mixed
- $lti13_privkey : mixed
- $lti13_kid : mixed
- $lti13_token_audience : mixed
- $deployment_id : mixed
- $debug_log : array<string|int, mixed> = false
-
An optional array passed by reference. Actions taken will be logged into this array.
Return values
mixed —Returns the token (string) or false on error.
getLineItemsToken()
Retrieve a LineItems token
public
static getLineItemsToken(mixed $subject, mixed $lti13_token_url, mixed $lti13_privkey, mixed $lti13_kid, mixed $lti13_token_audience, mixed $deployment_id[, array<string|int, mixed> &$debug_log = false ]) : mixed
Parameters
- $subject : mixed
- $lti13_token_url : mixed
- $lti13_privkey : mixed
- $lti13_kid : mixed
- $lti13_token_audience : mixed
- $deployment_id : mixed
- $debug_log : array<string|int, mixed> = false
-
An optional array passed by reference. Actions taken will be logged into this array.
Return values
mixed —Returns the token (string) or false on error.
getLTI11TransitionBase()
Compute the base string for a Launch JWT
public
static getLTI11TransitionBase(object $lj) : string
See: https://www.imsglobal.org/spec/lti/v1p3/migr#lti-1-1-migration-claim
Parameters
- $lj : object
-
The Launch JSON Web Token with the LTI 1.1 transition data
Return values
string —This is null if the base string cannot be computed
getNRPSToken()
Retrieve a Names and Roles Provisioning Service (NRPS) token
public
static getNRPSToken(mixed $subject, mixed $lti13_token_url, mixed $lti13_privkey, mixed $lti13_kid, mixed $lti13_token_audience, mixed $deployment_id[, array<string|int, mixed> &$debug_log = false ]) : mixed
Parameters
- $subject : mixed
- $lti13_token_url : mixed
- $lti13_privkey : mixed
- $lti13_kid : mixed
- $lti13_token_audience : mixed
- $deployment_id : mixed
- $debug_log : array<string|int, mixed> = false
-
An optional array passed by reference. Actions taken will be logged into this array.
Return values
mixed —Returns the token (string) or false on error.
getNRPSWithSourceDidsToken()
Retrieve a Names and Roles Provisioning Service (NRPS) token with source_dids
public
static getNRPSWithSourceDidsToken(mixed $subject, mixed $lti13_token_url, mixed $lti13_privkey, mixed $lti13_kid, mixed $lti13_token_audience, mixed $deployment_id[, array<string|int, mixed> &$debug_log = false ]) : mixed
This should require both the lineitems and grade permission I think. But some clarification is needed to make sure this is done correctly.
Parameters
- $subject : mixed
- $lti13_token_url : mixed
- $lti13_privkey : mixed
- $lti13_kid : mixed
- $lti13_token_audience : mixed
- $deployment_id : mixed
- $debug_log : array<string|int, mixed> = false
-
An optional array passed by reference. Actions taken will be logged into this array.
Return values
mixed —Returns the token (string) or false on error.
handle_curl_error()
Handle a curl that fails
public
static handle_curl_error(object $ch, mixed &$debug_log) : string
Parameters
- $ch : object
-
The curl handle that just had an error
- $debug_log : mixed
Return values
string —The error message
isRequest()
Returns true if this is an LTI 1.3 message with minimum values to meet the protocol
public
static isRequest([array<string|int, mixed> $request_data = false ]) : Returns
Parameters
- $request_data : array<string|int, mixed> = false
-
An optional prarameter if you want to pull the data from somewhere other than $_REQUEST.
Return values
Returns —true if this has a valid JWT, false if this is not a JWT at all.
isRequestDetail()
Returns true if this is an LTI 1.3 message with minimum values to meet the protocol
public
static isRequestDetail([array<string|int, mixed> $request_data = false ]) : Returns
Parameters
- $request_data : array<string|int, mixed> = false
-
An optional prarameter if you want to pull the data from somewhere other than $_REQUEST.
Return values
Returns —true if this has a valid JWT, false if this is not a JWT at all, or a string with an error message if this parses as a JWT but is missing required data.
isValidMessageType()
Check the incoming message type
public
static isValidMessageType(string $lti_message_type) : bool
Parameters
- $lti_message_type : string
-
The incoming message type from the request.
Return values
bool —True if this is an LTI 1.1 or LTI 1.3 message type.
isValidVersion()
Check the incoming message version
public
static isValidVersion(string $lti_version) : bool
Parameters
- $lti_version : string
-
The incoming message type from the request.
Return values
bool —True if this is an LTI 1.1 or LTI 2.0 message version.
jonPostel()
Apply Jon Postel's Law as appropriate
public
static jonPostel(object $body, array<string|int, mixed> &$failures) : mixed
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.
Parameters
- $body : object
-
The body of the JWT
- $failures : array<string|int, mixed>
-
A string array of failures (pass by reference)
loadGroups()
Load the groups if we can get them from the LMS
public
static loadGroups(string $context_groups_url, mixed $access_token[, array<string|int, mixed> &$debug_log = false ]) : mixed
Parameters
- $context_groups_url : string
-
The REST endpoint for memberships
- $access_token : mixed
-
The access token for this request
- $debug_log : array<string|int, mixed> = false
-
If this is an array, debug information is returned as the process progresses.
Return values
mixed —If this works it returns the NRPS object. If it fails, it returns a string.
loadLineItem()
Load the detiail for a lineitem from the LMS
public
static loadLineItem(mixed $lineitem_url, mixed $access_token[, mixed &$debug_log = false ]) : mixed
Parameters
- $lineitem_url : mixed
-
The REST endpoint (id) for this line item
- $access_token : mixed
-
The access token for this request
- $debug_log : mixed = false
-
Returns a log of actions taken
Return values
mixed —If this works it returns the LineItem object. If it fails, it returns a string.
loadLineItems()
Load our lineitems from the LMS
public
static loadLineItems(mixed $lineitems_url, mixed $access_token[, mixed &$debug_log = false ]) : mixed
Parameters
- $lineitems_url : mixed
-
The REST endpoint (id) for the line items
- $access_token : mixed
-
The access token for this request
- $debug_log : mixed = false
-
Returns a log of actions taken
Return values
mixed —If this works it returns the LineItems array. If it fails, it returns a string.
loadNRPS()
Load the memberships and roles if we can get it from the LMS
public
static loadNRPS(string $membership_url, mixed $access_token[, array<string|int, mixed> &$debug_log = false ][, int $maxPages = 0 ][, int|null &$http_status = null ]) : mixed
Parameters
- $membership_url : string
-
The REST endpoint for memberships
- $access_token : mixed
-
The access token for this request
- $debug_log : array<string|int, mixed> = false
-
If this is an array, debug information is returned as the process progresses.
- $maxPages : int = 0
-
Stop after this many pages. 0 follows every next link. A partial result sets truncated on the object. Callers that omit this keep the previous all-or-nothing return.
- $http_status : int|null = null
-
Last HTTP status, when the server answered.
Return values
mixed —If this works it returns the NRPS object. If it fails, it returns a string.
loadResults()
Load the results for a line item
public
static loadResults(mixed $lineitem_url, mixed $access_token[, mixed &$debug_log = false ]) : mixed
Parameters
- $lineitem_url : mixed
-
The REST endpoint (id) for this line item
- $access_token : mixed
-
The access token for this request
- $debug_log : mixed = false
-
Returns a log of actions taken
Return values
mixed —If this works it returns the Results array. If it fails, it returns a string.
parse_jwt()
Parse and validate a raw JWT
public
static parse_jwt(string $raw_jwt[, bool $required_fields = true ]) : mixed
Parameters
- $raw_jwt : string
-
The encoded JWT (a string)
- $required_fields : bool = true
-
Whether to throw an error if the required fields are missing. You can set this to false if you just want to parse and dump a JWT for debugging.
Return values
mixed —The parsed fields in an object as long as there are no errors. If there are errors, a string with the error message is returned.
raw_jwt()
Find the JWT in the request data
public
static raw_jwt([array<string|int, mixed> $request_data = false ]) : string
Parameters
- $request_data : array<string|int, mixed> = false
-
An optional prarameter if you want to pull the data from somewhere other than $_REQUEST.
Return values
string —The JWT from the request or false if there is no JWT.
sendLineItemResult()
Send a line item result
public
static sendLineItemResult(mixed $user_id, mixed $grade, mixed $scoreMaximum, mixed $comment, mixed $lineitem_url, mixed $access_token[, array<string|int, mixed> $extra = false ][, array<string|int, mixed> &$debug_log = false ]) : mixed
Parameters
- $user_id : mixed
-
The user for this grade
- $grade : mixed
-
Value to send
- $scoreMaximum : mixed
-
The amount that $grade is realative to
- $comment : mixed
-
An optional comment
- $lineitem_url : mixed
-
The REST endpoint (id) for this line item
- $access_token : mixed
-
The access token for this request
- $extra : array<string|int, mixed> = false
-
A set of key value extensions to be added/replaced in the request
- $debug_log : array<string|int, mixed> = false
-
An optional array passed by reference. Actions taken will be logged into this array.
Return values
mixed —Returns the token (string) or false on error.
setUserAgentCurl()
public
static setUserAgentCurl(mixed $ch) : mixed
Parameters
- $ch : mixed
signLTI11Transition()
Compute the OAuth signature for an LTI 1.3 Launch JWT
public
static signLTI11Transition(object $lj, string $secret) : string
See: https://www.imsglobal.org/spec/lti/v1p3/migr#lti-1-1-migration-claim
Parameters
- $lj : object
-
The Launch JSON Web Token with the LTI 11 transition data
- $secret : string
-
The OAuth secret
Return values
string —This is null if the signature cannot be computed
updateLineItem()
Update a lineitem in the LMS
public
static updateLineItem(mixed $lineitem_url, mixed $access_token, mixed $lineitem[, mixed &$debug_log = false ]) : mixed
Parameters
- $lineitem_url : mixed
-
The REST endpoint (id) for this line item
- $access_token : mixed
-
The access token for this request
- $lineitem : mixed
- $debug_log : mixed = false
-
Returns a log of actions taken
Return values
mixed —If this works it returns true. If it fails, it returns a string.
verifyPublicKey()
Verify the Public Key for this request
public
static verifyPublicKey(string $raw_jwt, string $public_key[, string $algs = false ]) : mixed
Parameters
- $raw_jwt : string
-
The raw JWT from the request
- $public_key : string
-
The public key
- $algs : string = false
-
The algorithm to use for validating the key.
Return values
mixed —This returns true if the request verified. If the request did not verify, this returns the exception that was generated.
partialOrError()
Keep members already loaded when a later page fails and a page cap is set.
private
static partialOrError(object|null $loaded, int $maxPages, string $status, array<string|int, mixed>|false &$debug_log) : object|string
Parameters
- $loaded : object|null
- $maxPages : int
- $status : string
- $debug_log : array<string|int, mixed>|false