LTI Integration Library 5.0.0-rc2
PHP class library for building LTI integrations
 
Loading...
Searching...
No Matches
Tool Class Reference

Class to represent an LTI Tool. More...

Inheritance diagram for Tool:
System ApiHook ToolProvider

Public Member Functions

 __construct ($dataConnector=null)
 Class constructor.
 
 initialize ()
 Initialise the tool.
 
bool save ()
 Save the tool to the database.
 
bool delete ()
 Delete the tool from the database.
 
array getMessageParameters ($strictMode=false, $disableCookieCheck=false, $generateWarnings=false)
 Get the message parameters.
 
 handleRequest ($strictMode=false, $disableCookieCheck=false, $generateWarnings=false)
 Process an incoming request.
 
 setParameterConstraint ($name, $required=true, $maxLength=null, $messageTypes=null)
 Add a parameter constraint to be checked on launch.
 
array getConsumers ()
 Get an array of defined tool consumers.
 
array getPlatforms ()
 Get an array of defined platforms.
 
object findService ($format, $methods)
 Find an offered service based on a media type and HTTP action(s)
 
bool doToolProxyService ()
 Send the tool proxy to the platform.
 
- Public Member Functions inherited from System
int null getRecordId ()
 Get the system record ID.
 
 setRecordId ($id)
 Sets the system record ID.
 
string getKey ()
 Get the consumer key.
 
 setKey ($key)
 Set the consumer key.
 
string getSetting ($name, $default='')
 Get a setting value.
 
 setSetting ($name, $value=null)
 Set a setting value.
 
array getSettings ()
 Get an array of all setting values.
 
 setSettings ($settings)
 Set an array of all setting values.
 
bool saveSettings ()
 Save setting values.
 
bool hasJwt ()
 Check whether a JWT exists.
 
ClientInterface getJwt ()
 Get the JWT.
 
array getRawParameters ()
 Get the raw POST parameters.
 
array getMessageClaims ($fullyQualified=false)
 Get the message claims.
 
array string signParameters ($url, $type, $version, $params)
 Add the signature to an LTI message.
 
array string signMessage (&$url, $type, $version, $params, $loginHint=null, $ltiMessageHint=null)
 Add the signature to an LTI message.
 
string sendMessage ($url, $type, $messageParams, $target='', $userId=null, $hint=null)
 Generate a web page containing an auto-submitted form of LTI message parameters.
 
string signServiceRequest ($url, $method, $type, $data=null)
 Generates the headers for an LTI service request.
 
HttpMessage doServiceRequest ($service, $method, $format, $data)
 Perform a service request.
 
bool useOAuth1 ()
 Determine whether this consumer is using the OAuth 1 security model.
 
mixed addSignature ($endpoint, $data, $method='POST', $type=null, $nonce='', $hash=null, $timestamp=null)
 Add the signature to an array of message parameters or to a header string.
 
bool checkMessage ()
 Verify the required properties of an LTI message.
 
bool verifySignature ()
 Verify the signature of a message.
 

Static Public Member Functions

static string sendForm ($url, $params, $target='')
 Generate a web page containing an auto-submitted form of parameters.
 
static Tool fromConsumerKey ($key=null, $dataConnector=null, $autoEnable=false)
 Load the tool from the database by its consumer key.
 
static Tool fromInitiateLoginUrl ($initiateLoginUrl, $dataConnector=null, $autoEnable=false)
 Load the tool from the database by its initiate login URL.
 
static Tool fromRecordId ($id, $dataConnector)
 Load the tool from the database by its record ID.
 
- Static Public Member Functions inherited from System
static array parseRoles ($roles, $ltiVersion=Util::LTI_VERSION1, $addPrincipalRole=false)
 Parse a set of roles to comply with a specified version of LTI.
 
- Static Public Member Functions inherited from ApiHook
static void registerApiHook ($hookName, $familyCode, $className)
 Register the availability of an API hook.
 

Public Attributes

const CONNECTION_ERROR_MESSAGE = 'Sorry, there was an error connecting you to the application.'
 Default connection error message.
 
const ID_SCOPE_ID_ONLY = 0
 Use ID value only.
 
const ID_SCOPE_GLOBAL = 1
 Prefix an ID with the consumer key.
 
const ID_SCOPE_CONTEXT = 2
 Prefix the ID with the consumer key and context ID.
 
const ID_SCOPE_RESOURCE = 3
 Prefix the ID with the consumer key and resource ID.
 
const ID_SCOPE_SEPARATOR = ':'
 Character used to separate each element of an ID.
 
ToolConsumer null $consumer = null
 Tool consumer object.
 
Platform null $platform = null
 Platform object.
 
string null $returnUrl = null
 Return URL provided by platform.
 
UserResult null $userResult = null
 UserResult object.
 
ResourceLink null $resourceLink = null
 Resource link object.
 
Context null $context = null
 Context object.
 
string $defaultEmail = ''
 Default email domain.
 
int $idScope = self::ID_SCOPE_ID_ONLY
 Scope to use for user IDs.
 
bool $allowSharing = false
 Whether shared resource link arrangements are permitted.
 
string $message = null
 Message for last request processed.
 
array $warnings = array()
 Warnings relating to last request processed.
 
string null $baseUrl = null
 Base URL for tool service.
 
Item null $vendor = null
 Vendor details.
 
Item null $product = null
 Product details.
 
array null $requiredServices = null
 Services required by Tool.
 
array null $optionalServices = null
 Optional services used by Tool.
 
array null $resourceHandlers = null
 Resource handlers for Tool.
 
string null $messageUrl = null
 Message URL for Tool.
 
string null $initiateLoginUrl = null
 Initiate Login request URL for Tool.
 
array null $redirectionUris = null
 Redirection URIs for Tool.
 
- Public Attributes inherited from System
bool $ok = true
 True if the last request was successful.
 
string null $secret = null
 Shared secret.
 
string $signatureMethod = 'HMAC-SHA1'
 Method used for signing messages.
 
string $encryptionMethod = ''
 Algorithm used for encrypting messages.
 
DataConnector null $dataConnector = null
 Data connector object.
 
string null $rsaKey = null
 RSA key in PEM or JSON format.
 
array $requiredScopes = array()
 Scopes to request when obtaining an access token.
 
string null $kid = null
 Key ID.
 
string null $jku = null
 Endpoint for public key.
 
string null $reason = null
 Error message for last request processed.
 
array $details = array()
 Details for error message relating to last request processed.
 
bool $debugMode = false
 Whether debug level messages are to be reported.
 
bool $enabled = false
 Whether the system instance is enabled to accept connection requests.
 
int null $enableFrom = null
 Timestamp from which the the system instance is enabled to accept connection requests.
 
int null $enableUntil = null
 Timestamp until which the system instance is enabled to accept connection requests.
 
int null $lastAccess = null
 Timestamp for date of last connection to this system.
 
int null $created = null
 Timestamp for when the object was created.
 
int null $updated = null
 Timestamp for when the object was last updated.
 

Static Public Attributes

static $MESSAGE_TYPES
 List of supported incoming message types.
 
static Tool null $defaultTool = null
 Default tool for use with service requests.
 
static bool $authenticateUsingGet = false
 Use GET method for authentication request messages when true.
 
static int $stateLife = 10
 Life in seconds for the state value issued during the OIDC login process.
 
static int $postMessageTimeoutDelay = 20
 Period in milliseconds to wait for a response to a postMessage.
 
- Static Public Attributes inherited from ApiHook
static $USER_ID_HOOK = "UserId"
 User Id hook name.
 
static $CONTEXT_ID_HOOK = "ContextId"
 Context Id hook name.
 
static $GROUPS_SERVICE_HOOK = "Groups"
 Course Groups service hook name.
 
static $MEMBERSHIPS_SERVICE_HOOK = "Memberships"
 Memberships service hook name.
 
static $OUTCOMES_SERVICE_HOOK = "Outcomes"
 Outcomes service hook name.
 
static $TOOL_SETTINGS_SERVICE_HOOK = "ToolSettings"
 Tool Settings service hook name.
 
static $ACCESS_TOKEN_SERVICE_HOOK = "AccessToken"
 Access Token service hook name.
 

Protected Member Functions

 onLaunch ()
 Process a valid launch request.
 
 onConfigure ()
 Process a valid configure request.
 
 onDashboard ()
 Process a valid dashboard request.
 
 onContentItem ()
 Process a valid content-item request.
 
 onContentItemUpdate ()
 Process a valid content-item update request.
 
 onSubmissionReview ()
 Process a valid submission review request.
 
 onRegister ()
 Process a valid tool proxy registration request.
 
 onRegistration ()
 Process a dynamic registration request.
 
 onLtiStartProctoring ()
 Process a valid start proctoring request.
 
 onLtiEndAssessment ()
 Process a valid end assessment request.
 
 onInitiateLogin ($requestParameters, &$authParameters)
 Process a login initiation request.
 
 onAuthenticate ($state, $nonce, $usePlatformStorage)
 Process response to an authentication request.
 
 onResetSessionId ()
 Process a change in the session ID.
 
 onError ()
 Process a response to an invalid request.
 
array null getPlatformConfiguration ()
 Fetch a platform's configuration data.
 
array getConfiguration ($platformConfig)
 Prepare the tool's configuration data.
 
array sendRegistration ($platformConfig, $toolConfig)
 Send the tool registration to the platform.
 
Platform getPlatformToRegister ($platformConfig, $registrationConfig, $doSave=true)
 Initialise the platform to be registered.
 
 getRegistrationResponsePage ($toolConfig)
 Prepare the page to complete a registration request.
 

Protected Attributes

string null $redirectUrl = null
 URL to redirect user to on successful completion of the request.
 
array null $mediaTypes = null
 Media types accepted by the platform.
 
array null $contentTypes = null
 Content item types accepted by the platform.
 
array null $fileTypes = null
 File types accepted by the platform.
 
array null $documentTargets = null
 Document targets accepted by the platform.
 
string null $output = null
 Default HTML to be displayed on a successful completion of the request.
 
string null $errorOutput = null
 HTML to be displayed on an unsuccessful completion of the request and no return URL is available.
 
- Protected Attributes inherited from System
JWS null $jwt = null
 JWT object, if any.
 
array $rawParameters = null
 Raw message parameters.
 
array null $messageParameters = null
 LTI message parameters.
 

Detailed Description

Class to represent an LTI Tool.

Author
Stephen P Vickers steph.nosp@m.en@s.nosp@m.pvsof.nosp@m.twar.nosp@m.eprod.nosp@m.ucts.nosp@m..com
Licence: http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3

Constructor & Destructor Documentation

◆ __construct()

__construct (   $dataConnector = null)

Class constructor.

Parameters
DataConnector$dataConnectorObject containing a database connection object

Reimplemented in ToolProvider.

Member Function Documentation

◆ delete()

bool delete ( )

Delete the tool from the database.

Returns
bool True if the object was successfully deleted

◆ doToolProxyService()

bool doToolProxyService ( )

Send the tool proxy to the platform.

Returns
bool True if the tool proxy was accepted

◆ findService()

object findService (   $format,
  $methods 
)

Find an offered service based on a media type and HTTP action(s)

Parameters
string$formatMedia type required
array$methodsArray of HTTP actions required
Returns
object The service object

References Tool\getPlatforms(), and Util\logDebug().

◆ fromConsumerKey()

static Tool fromConsumerKey (   $key = null,
  $dataConnector = null,
  $autoEnable = false 
)
static

Load the tool from the database by its consumer key.

Parameters
string$keyConsumer key
DataConnector$dataConnectorA data connector object
bool$autoEnabletrue if the tool is to be enabled automatically (optional, default is false)
Returns
Tool The tool object

References System\$enabled.

◆ fromInitiateLoginUrl()

static Tool fromInitiateLoginUrl (   $initiateLoginUrl,
  $dataConnector = null,
  $autoEnable = false 
)
static

Load the tool from the database by its initiate login URL.

Parameters
string$initiateLoginUrlThe initiate login URL
DataConnector$dataConnectorA data connector object
bool$autoEnableTrue if the tool is to be enabled automatically (optional, default is false)
Returns
Tool The tool object

◆ fromRecordId()

static Tool fromRecordId (   $id,
  $dataConnector 
)
static

Load the tool from the database by its record ID.

Parameters
string$idThe tool record ID
DataConnector$dataConnectorA data connector object
Returns
Tool The tool object

◆ getConfiguration()

array getConfiguration (   $platformConfig)
protected

Prepare the tool's configuration data.

Parameters
array$platformConfigPlatform configuration data
Returns
array Tool configuration data

◆ getConsumers()

array getConsumers ( )

Get an array of defined tool consumers.

Deprecated:
Use getPlatforms() instead
See also
Tool::getPlatforms()
Returns
array Array of ToolConsumer objects

◆ getMessageParameters()

array getMessageParameters (   $strictMode = false,
  $disableCookieCheck = false,
  $generateWarnings = false 
)

Get the message parameters.

Parameters
bool$strictModeTrue if full compliance with the LTI specification is required (optional, default is false)
bool$disableCookieCheckTrue if no cookie check should be made (optional, default is false)
bool$generateWarningsTrue if warning messages should be generated (optional, default is false)
Returns
array The message parameter array

◆ getPlatformConfiguration()

array null getPlatformConfiguration ( )
protected

Fetch a platform's configuration data.

Returns
array|null Platform configuration data

◆ getPlatforms()

array getPlatforms ( )

Get an array of defined platforms.

Returns
array Array of Platform objects

Referenced by Tool\findService().

◆ getPlatformToRegister()

Platform getPlatformToRegister (   $platformConfig,
  $registrationConfig,
  $doSave = true 
)
protected

Initialise the platform to be registered.

Parameters
array$platformConfigPlatform configuration data
array$registrationConfigRegistration data
bool$doSaveTrue if the platform should be saved (optional, default is true)
Returns
Platform Platform object

References Util\getRequestParameters().

◆ getRegistrationResponsePage()

getRegistrationResponsePage (   $toolConfig)
protected

Prepare the page to complete a registration request.

Parameters
array$toolConfigTool configuration data

◆ handleRequest()

handleRequest (   $strictMode = false,
  $disableCookieCheck = false,
  $generateWarnings = false 
)

Process an incoming request.

Parameters
bool$strictModeTrue if full compliance with the LTI specification is required (optional, default is false)
bool$disableCookieCheckTrue if no cookie check should be made (optional, default is false)
bool$generateWarningsTrue if warning messages should be generated (optional, default is false)

◆ onAuthenticate()

onAuthenticate (   $state,
  $nonce,
  $usePlatformStorage 
)
protected

Process response to an authentication request.

Parameters
string$stateState value
string$nonceNonce value
bool$usePlatformStorageTrue if platform storage is being used

References Tool\onError().

◆ onInitiateLogin()

onInitiateLogin (   $requestParameters,
$authParameters 
)
protected

Process a login initiation request.

Parameters
array$requestParametersRequest parameters
array$authParametersAuthentication request parameters

◆ save()

bool save ( )

Save the tool to the database.

Returns
bool True if the object was successfully saved

◆ sendForm()

static string sendForm (   $url,
  $params,
  $target = '' 
)
static

Generate a web page containing an auto-submitted form of parameters.

Deprecated:
Use Util::sendForm() instead
See also
Util::sendForm()
Parameters
string$urlURL to which the form should be submitted
array$paramsArray of form parameters
string$targetName of target (optional)
Returns
string

◆ sendRegistration()

array sendRegistration (   $platformConfig,
  $toolConfig 
)
protected

Send the tool registration to the platform.

Parameters
array$platformConfigPlatform configuration data
array$toolConfigTool configuration data
Returns
array Registration data

◆ setParameterConstraint()

setParameterConstraint (   $name,
  $required = true,
  $maxLength = null,
  $messageTypes = null 
)

Add a parameter constraint to be checked on launch.

Parameters
string$nameName of parameter to be checked
bool$requiredTrue if parameter is required (optional, default is true)
int$maxLengthMaximum permitted length of parameter value (optional, default is null)
array$messageTypesArray of message types to which the constraint applies (optional, default is all)

Member Data Documentation

◆ $allowSharing

bool $allowSharing = false

Whether shared resource link arrangements are permitted.

$allowSharing

◆ $authenticateUsingGet

bool $authenticateUsingGet = false
static

Use GET method for authentication request messages when true.

$authenticateUsingGet

◆ $baseUrl

string null $baseUrl = null

Base URL for tool service.

$baseUrl

◆ $consumer

ToolConsumer null $consumer = null

Tool consumer object.

Deprecated:
Use Tool::$platform instead
See also
platform

$consumer

◆ $contentTypes

array null $contentTypes = null
protected

Content item types accepted by the platform.

$contentTypes

◆ $context

Context null $context = null

Context object.

$context

◆ $defaultEmail

string $defaultEmail = ''

Default email domain.

$defaultEmail

◆ $defaultTool

Tool null $defaultTool = null
static

Default tool for use with service requests.

$defaultTool

◆ $documentTargets

array null $documentTargets = null
protected

Document targets accepted by the platform.

$documentTargets

◆ $errorOutput

string null $errorOutput = null
protected

HTML to be displayed on an unsuccessful completion of the request and no return URL is available.

$errorOutput

◆ $fileTypes

array null $fileTypes = null
protected

File types accepted by the platform.

$fileTypes

◆ $idScope

int $idScope = self::ID_SCOPE_ID_ONLY

Scope to use for user IDs.

$idScope

◆ $initiateLoginUrl

string null $initiateLoginUrl = null

Initiate Login request URL for Tool.

$initiateLoginUrl

◆ $mediaTypes

array null $mediaTypes = null
protected

Media types accepted by the platform.

$mediaTypes

◆ $message

string $message = null

Message for last request processed.

$message

◆ $MESSAGE_TYPES

$MESSAGE_TYPES
static
Initial value:
= array(
'basic-lti-launch-request',
'ConfigureLaunchRequest',
'DashboardRequest',
'ContentItemSelectionRequest',
'ContentItemUpdateRequest',
'LtiSubmissionReviewRequest',
'ToolProxyRegistrationRequest',
'LtiStartProctoring',
'LtiEndAssessment'
)

List of supported incoming message types.

◆ $messageUrl

string null $messageUrl = null

Message URL for Tool.

$messageUrl

◆ $optionalServices

array null $optionalServices = null

Optional services used by Tool.

$optionalServices

◆ $output

string null $output = null
protected

Default HTML to be displayed on a successful completion of the request.

$output

◆ $platform

Platform null $platform = null

Platform object.

$platform

Referenced by Tool\initialize().

◆ $postMessageTimeoutDelay

int $postMessageTimeoutDelay = 20
static

Period in milliseconds to wait for a response to a postMessage.

$postMessageTimeoutDelay

◆ $product

Item null $product = null

Product details.

$product

◆ $redirectionUris

array null $redirectionUris = null

Redirection URIs for Tool.

$redirectionUris

◆ $redirectUrl

string null $redirectUrl = null
protected

URL to redirect user to on successful completion of the request.

$redirectUrl

◆ $requiredServices

array null $requiredServices = null

Services required by Tool.

$requiredServices

◆ $resourceHandlers

array null $resourceHandlers = null

Resource handlers for Tool.

$resourceHandlers

◆ $resourceLink

ResourceLink null $resourceLink = null

Resource link object.

$resourceLink

◆ $returnUrl

string null $returnUrl = null

Return URL provided by platform.

$returnUrl

◆ $stateLife

int $stateLife = 10
static

Life in seconds for the state value issued during the OIDC login process.

$stateLife

◆ $userResult

UserResult null $userResult = null

UserResult object.

$userResult

◆ $vendor

Item null $vendor = null

Vendor details.

$vendor

◆ $warnings

array $warnings = array()

Warnings relating to last request processed.

$warnings


The documentation for this class was generated from the following file: