LTI Integration Library 5.2.0
PHP class library for building LTI integrations
 
Loading...
Searching...
No Matches
ceLTIc\LTI\System Class Reference

Class to represent an LTI system. More...

+ Inheritance diagram for ceLTIc\LTI\System:

Public Member Functions

int string null getRecordId ()
 Get the system record ID.
 
void setRecordId (int|string|null $id)
 Sets the system record ID.
 
string null getKey ()
 Get the consumer key.
 
void setKey (?string $key)
 Set the consumer key.
 
string null getSetting (string $name, ?string $default='')
 Get a setting value.
 
void setSetting (string $name, string|array|null $value=null)
 Set a setting value.
 
array getSettings ()
 Get an array of all setting values.
 
void setSettings (array $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 (bool $fullyQualified=false)
 Get the message claims.
 
array string signParameters (string $url, string $type, string $ltiVersionString, array $params)
 Add the signature to an LTI message.
 
array string signMessage (string &$url, string $type, string $ltiVersionString, array $params, ?string $loginHint=null, ?string $ltiMessageHint=null)
 Add the signature to an LTI message.
 
string sendMessage (string $url, string $type, array $messageParams, string $target='', ?string $userId=null, ?string $hint=null)
 Generate a web page containing an auto-submitted form of LTI message parameters.
 
array string signServiceRequest (string $url, string $method, string $type, array|string|null $data=null)
 Generates the headers for an LTI service request.
 
HttpMessage doServiceRequest (ServiceDefinition $service, string $method, string $format, array|string $data)
 Perform a service request.
 
bool useOAuth1 ()
 Determine whether this consumer is using the OAuth 1 security model.
 
array string addSignature (string $endpoint, array|string|null $data, string $method='POST', ?string $type=null, ?string $nonce='', ?string $hash=null, ?int $timestamp=null)
 Add the signature to an array of message parameters or to a header string.
 
string null getBaseString ()
 Get the last signature base string.
 
bool checkMessage (bool $generateWarnings=false)
 Verify the required properties of an LTI message.
 
bool verifySignature ()
 Verify the signature of a message.
 
bool setReason (string $reason)
 Set the error reason.
 

Static Public Member Functions

static array parseRoles (array|string $roles, LtiVersion $ltiVersion=LtiVersion::V1, bool $addPrincipalRole=false)
 Parse a set of roles to comply with a specified version of LTI.
 

Public Attributes

bool $ok = true
 True if the last request was successful.
 
LtiVersion $ltiVersion = null
 LTI version.
 
string $name = null
 Local name of platform/tool.
 
string $secret = null
 Shared secret.
 
string $signatureMethod = 'HMAC-SHA1'
 Method used for signing messages.
 
string $encryptionMethod = ''
 Algorithm used for encrypting messages.
 
DataConnector $dataConnector = null
 Data connector object.
 
string $rsaKey = null
 RSA key in PEM or JSON format.
 
array $requiredScopes = []
 Scopes to request when obtaining an access token.
 
string $kid = null
 Key ID.
 
string $jku = null
 Endpoint for public key.
 
string $reason = null
 Error message for last request processed.
 
array $details = []
 Details for error message relating to last request processed.
 
array $warnings = []
 Warnings 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 $enableFrom = null
 Timestamp from which the the system instance is enabled to accept connection requests.
 
int $enableUntil = null
 Timestamp until which the system instance is enabled to accept connection requests.
 
int $lastAccess = null
 Timestamp for date of last connection to this system.
 
int $created = null
 Timestamp for when the object was created.
 
int $updated = null
 Timestamp for when the object was last updated.
 
IdScope $idScope = IdScope::IdOnly
 Default scope to use when generating an Id value for a user.
 

Protected Attributes

ClientInterface $jwt = null
 JWT ClientInterface object.
 
array $rawParameters = null
 Raw message parameters.
 
array $messageParameters = null
 LTI message parameters.
 

Detailed Description

Class to represent an LTI system.

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

Member Function Documentation

◆ addSignature()

array string ceLTIc\LTI\System::addSignature ( string $endpoint,
array|string|null $data,
string $method = 'POST',
?string $type = null,
?string $nonce = '',
?string $hash = null,
?int $timestamp = null )

Add the signature to an array of message parameters or to a header string.

Parameters
string$endpointURL to which message is being sent
array | string | null$dataData to be passed
string$methodHTTP method
string | null$typeContent type of data being passed
string | null$nonceNonce value for JWT
string | null$hashOAuth body hash value
int | null$timestampTimestamp
Returns
array|string Array of signed message parameters or header string

References setReason().

Referenced by sendMessage().

◆ checkMessage()

bool ceLTIc\LTI\System::checkMessage ( bool $generateWarnings = false)

Verify the required properties of an LTI message.

Parameters
bool$generateWarningsTrue if warning messages should be generated
Returns
bool True if it is a valid LTI message

References $secret.

Referenced by useOAuth1().

◆ doServiceRequest()

HttpMessage ceLTIc\LTI\System::doServiceRequest ( ServiceDefinition $service,
string $method,
string $format,
array|string $data )

Perform a service request.

Parameters
ServiceDefinition$serviceService object to be executed
string$methodHTTP action
string$formatMedia type
array | string$dataArray of parameters or body string
Returns
HttpMessage HTTP object containing request and response details

References useOAuth1().

Referenced by sendMessage().

◆ getBaseString()

string null ceLTIc\LTI\System::getBaseString ( )

Get the last signature base string.

Returns
string|null Signature base string

◆ getJwt()

ClientInterface ceLTIc\LTI\System::getJwt ( )

Get the JWT.

Returns
ClientInterface The JWT

References $messageParameters.

◆ getKey()

string null ceLTIc\LTI\System::getKey ( )

Get the consumer key.

Returns
string|null Consumer key value

References $name, getSetting(), and setSetting().

Referenced by ceLTIc\LTI\ResourceLink\getContextId().

◆ getMessageClaims()

array ceLTIc\LTI\System::getMessageClaims ( bool $fullyQualified = false)

Get the message claims.

Parameters
bool$fullyQualifiedTrue if claims should be fully qualified rather than grouped (default is false)
Returns
array| null The message claim array

◆ getRawParameters()

array ceLTIc\LTI\System::getRawParameters ( )

Get the raw POST parameters.

Returns
array The POST parameter array

References $messageParameters.

Referenced by setSettings().

◆ getRecordId()

◆ getSetting()

string null ceLTIc\LTI\System::getSetting ( string $name,
?string $default = '' )

Get a setting value.

Parameters
string$nameName of setting
string | null$defaultValue to return if the setting does not exist (optional, default is an empty string)
Returns
string|null Setting value

Referenced by ceLTIc\LTI\Platform\getAccessToken(), ceLTIc\LTI\Platform\getIsAvailable(), getKey(), getRecordId(), and ceLTIc\LTI\Platform\hasToolSettingsService().

◆ getSettings()

array ceLTIc\LTI\System::getSettings ( )

Get an array of all setting values.

Returns
array Associative array of setting values

◆ hasJwt()

bool ceLTIc\LTI\System::hasJwt ( )

Check whether a JWT exists.

Returns
bool True if a JWT exists

References $messageParameters, and ceLTIc\LTI\Util\MESSAGE_TYPE_MAPPING.

◆ parseRoles()

static array ceLTIc\LTI\System::parseRoles ( array|string $roles,
LtiVersion $ltiVersion = LtiVersion::V1,
bool $addPrincipalRole = false )
static

Parse a set of roles to comply with a specified version of LTI.

Parameters
array | string$rolesComma-separated list of roles or array of roles
LtiVersion$ltiVersionLTI version for roles being returned (optional, default is LTI-1p0)
bool$addPrincipalRoleAdd principal role when true (optional, default is false)
Returns
array Array of roles

References $ltiVersion.

◆ saveSettings()

bool ceLTIc\LTI\System::saveSettings ( )

Save setting values.

Returns
bool True if the settings were successfully saved

Referenced by setSetting().

◆ sendMessage()

string ceLTIc\LTI\System::sendMessage ( string $url,
string $type,
array $messageParams,
string $target = '',
?string $userId = null,
?string $hint = null )

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

Parameters
string$urlURL to which the form should be submitted
string$typeLTI message type
array$messageParamsArray of form parameters
string$targetName of target (optional)
string | null$userIdID of user (optional)
string | null$hintLTI message hint (optional, use null for none)
Returns
string

References addSignature(), doServiceRequest(), and ceLTIc\LTI\Util\jsonDecode().

◆ setKey()

void ceLTIc\LTI\System::setKey ( ?string $key)

Set the consumer key.

Parameters
string | null$keyConsumer key value

◆ setReason()

◆ setRecordId()

void ceLTIc\LTI\System::setRecordId ( int|string|null $id)

Sets the system record ID.

Parameters
int | string | null$idSystem record ID value

Referenced by ceLTIc\LTI\Tool\fromConsumerKey().

◆ setSetting()

void ceLTIc\LTI\System::setSetting ( string $name,
string|array|null $value = null )

Set a setting value.

Parameters
string$nameName of setting
string | array | null$valueValue to set, use an empty value to delete a setting (optional, default is null)

References $ok, and saveSettings().

Referenced by getKey().

◆ setSettings()

void ceLTIc\LTI\System::setSettings ( array $settings)

Set an array of all setting values.

Parameters
array$settingsAssociative array of setting values

References ceLTIc\LTI\OAuth\OAuthRequest\$POST_INPUT, getRawParameters(), and ceLTIc\LTI\OAuth\OAuthUtil\parse_parameters().

◆ signMessage()

array string ceLTIc\LTI\System::signMessage ( string & $url,
string $type,
string $ltiVersionString,
array $params,
?string $loginHint = null,
?string $ltiMessageHint = null )

Add the signature to an LTI message.

If the message is being sent from a platform using LTI 1.3, then the parameters and URL will be saved and replaced with an initiate login request.

Parameters
string$urlURL for message request
string$typeLTI message type
string$ltiVersionStringLTI version
array$paramsMessage parameters
string | null$loginHintID of user (optional)
string | null$ltiMessageHintLTI message hint (optional, use null for none)
Returns
array|string Array of signed message parameters or request headers

◆ signParameters()

array string ceLTIc\LTI\System::signParameters ( string $url,
string $type,
string $ltiVersionString,
array $params )

Add the signature to an LTI message.

Parameters
string$urlURL for message request
string$typeLTI message type
string$ltiVersionStringLTI version
array$paramsMessage parameters
Returns
array|string Array of signed message parameters or request headers

◆ signServiceRequest()

array string ceLTIc\LTI\System::signServiceRequest ( string $url,
string $method,
string $type,
array|string|null $data = null )

Generates the headers for an LTI service request.

Parameters
string$urlURL for message request
string$methodHTTP method
string$typeMedia type
array | string | null$dataData being passed in request body (optional)
Returns
array|string Headers to include with service request

References useOAuth1().

◆ useOAuth1()

bool ceLTIc\LTI\System::useOAuth1 ( )

Determine whether this consumer is using the OAuth 1 security model.

Returns
bool True if OAuth 1 security model should be used

References checkMessage(), and setReason().

Referenced by doServiceRequest(), and signServiceRequest().

◆ verifySignature()

bool ceLTIc\LTI\System::verifySignature ( )

Verify the signature of a message.

Returns
bool True if the signature is valid

References ceLTIc\LTI\OAuth\OAuthRequest\from_request().

Member Data Documentation

◆ $created

int ceLTIc\LTI\System::$created = null

Timestamp for when the object was created.

◆ $dataConnector

DataConnector ceLTIc\LTI\System::$dataConnector = null

◆ $debugMode

bool ceLTIc\LTI\System::$debugMode = false

Whether debug level messages are to be reported.

◆ $details

array ceLTIc\LTI\System::$details = []

Details for error message relating to last request processed.

◆ $enabled

bool ceLTIc\LTI\System::$enabled = false

Whether the system instance is enabled to accept connection requests.

Referenced by ceLTIc\LTI\Tool\getPlatformToRegister().

◆ $enableFrom

int ceLTIc\LTI\System::$enableFrom = null

Timestamp from which the the system instance is enabled to accept connection requests.

◆ $enableUntil

int ceLTIc\LTI\System::$enableUntil = null

Timestamp until which the system instance is enabled to accept connection requests.

◆ $encryptionMethod

string ceLTIc\LTI\System::$encryptionMethod = ''

Algorithm used for encrypting messages.

◆ $idScope

IdScope ceLTIc\LTI\System::$idScope = IdScope::IdOnly

Default scope to use when generating an Id value for a user.

◆ $jku

string ceLTIc\LTI\System::$jku = null

Endpoint for public key.

◆ $jwt

ClientInterface ceLTIc\LTI\System::$jwt = null
protected

JWT ClientInterface object.

◆ $kid

string ceLTIc\LTI\System::$kid = null

Key ID.

◆ $lastAccess

int ceLTIc\LTI\System::$lastAccess = null

Timestamp for date of last connection to this system.

◆ $ltiVersion

LtiVersion ceLTIc\LTI\System::$ltiVersion = null

LTI version.

Referenced by parseRoles().

◆ $messageParameters

array ceLTIc\LTI\System::$messageParameters = null
protected

LTI message parameters.

Referenced by getJwt(), getRawParameters(), and hasJwt().

◆ $name

string ceLTIc\LTI\System::$name = null

Local name of platform/tool.

Referenced by getKey(), and getRecordId().

◆ $ok

◆ $rawParameters

array ceLTIc\LTI\System::$rawParameters = null
protected

Raw message parameters.

◆ $reason

string ceLTIc\LTI\System::$reason = null

Error message for last request processed.

◆ $requiredScopes

array ceLTIc\LTI\System::$requiredScopes = []

Scopes to request when obtaining an access token.

◆ $rsaKey

string ceLTIc\LTI\System::$rsaKey = null

RSA key in PEM or JSON format.

Set to the private key for signing outgoing messages and service requests, and to the public key for verifying incoming messages and service requests.

◆ $secret

string ceLTIc\LTI\System::$secret = null

Shared secret.

Referenced by checkMessage(), and ceLTIc\LTI\Tool\findService().

◆ $signatureMethod

string ceLTIc\LTI\System::$signatureMethod = 'HMAC-SHA1'

Method used for signing messages.

◆ $updated

int ceLTIc\LTI\System::$updated = null

Timestamp for when the object was last updated.

◆ $warnings

array ceLTIc\LTI\System::$warnings = []

Warnings relating to last request processed.

Deprecated
Use Util::getMessages() instead