-
Notifications
You must be signed in to change notification settings - Fork 106
Fix several issues when using the library in Laravel #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
49a2085
DEV-8345 fix index and merge erics PR
dbhynds 0af27f1
DEV-8345 catch missing deployment id
dbhynds eebc53a
DEV-8345 remove unnecessary closing tags
dbhynds 328c4e7
DEV-8345 make cookie and cache interfaces as described
dbhynds 65eba92
DEV-8345 use firebase exception
dbhynds fd44a22
DEV-8345 dont var_dump
dbhynds ea60aed
DEV-8345 add consts
dbhynds 61d75e5
DEV-8345 remove more magic strings
dbhynds 4356b42
DEV-8345 add cookie const
dbhynds 7fd9ffa
DEV-8345 add missing version exception
dbhynds bdeafef
Throw exception if nonce is missing
EricTendian fae5b9b
Merge pull request #1 from EricTendian/patch-1
dbhynds 218719f
Merge branch 'master' into master
dbhynds 35e10f6
rename constants
dbhynds File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,9 @@ | ||
<?php | ||
namespace IMSGlobal\LTI; | ||
|
||
class Cache { | ||
|
||
private $cache; | ||
|
||
public function get_launch_data($key) { | ||
$this->load_cache(); | ||
return $this->cache[$key]; | ||
} | ||
|
||
public function cache_launch_data($key, $jwt_body) { | ||
$this->cache[$key] = $jwt_body; | ||
$this->save_cache(); | ||
return $this; | ||
} | ||
|
||
public function cache_nonce($nonce) { | ||
$this->cache['nonce'][$nonce] = true; | ||
$this->save_cache(); | ||
return $this; | ||
} | ||
|
||
public function check_nonce($nonce) { | ||
$this->load_cache(); | ||
if (!isset($this->cache['nonce'][$nonce])) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
private function load_cache() { | ||
$cache = file_get_contents(sys_get_temp_dir() . '/lti_cache.txt'); | ||
if (empty($cache)) { | ||
file_put_contents(sys_get_temp_dir() . '/lti_cache.txt', '{}'); | ||
$this->cache = []; | ||
} | ||
$this->cache = json_decode($cache, true); | ||
} | ||
|
||
private function save_cache() { | ||
file_put_contents(sys_get_temp_dir() . '/lti_cache.txt', json_encode($this->cache)); | ||
} | ||
interface Cache { | ||
public function get_launch_data($key); | ||
public function cache_launch_data($key, $jwt_body); | ||
public function cache_nonce($nonce); | ||
public function check_nonce($nonce); | ||
} | ||
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,7 @@ | ||
<?php | ||
namespace IMSGlobal\LTI; | ||
|
||
class Cookie { | ||
public function get_cookie($name) { | ||
if (isset($_COOKIE[$name])) { | ||
return $_COOKIE[$name]; | ||
} | ||
// Look for backup cookie if same site is not supported by the user's browser. | ||
if (isset($_COOKIE["LEGACY_" . $name])) { | ||
return $_COOKIE["LEGACY_" . $name]; | ||
} | ||
return false; | ||
} | ||
|
||
public function set_cookie($name, $value, $exp = 3600, $options = []) { | ||
$cookie_options = [ | ||
'expires' => time() + $exp | ||
]; | ||
|
||
// SameSite none and secure will be required for tools to work inside iframes | ||
$same_site_options = [ | ||
'samesite' => 'None', | ||
'secure' => true | ||
]; | ||
|
||
setcookie($name, $value, array_merge($cookie_options, $same_site_options, $options)); | ||
|
||
// Set a second fallback cookie in the event that "SameSite" is not supported | ||
setcookie("LEGACY_" . $name, $value, array_merge($cookie_options, $options)); | ||
return $this; | ||
} | ||
interface Cookie { | ||
public function get_cookie($name); | ||
public function set_cookie($name, $value, $exp = 3600, $options = []); | ||
} | ||
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,3 @@ public function find_registration_by_issuer($iss); | |
public function find_deployment($iss, $deployment_id); | ||
} | ||
|
||
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
namespace IMSGlobal\LTI; | ||
|
||
class ImsCache { | ||
|
||
private $cache; | ||
|
||
public function get_launch_data($key) { | ||
$this->load_cache(); | ||
return $this->cache[$key]; | ||
} | ||
|
||
public function cache_launch_data($key, $jwt_body) { | ||
$this->cache[$key] = $jwt_body; | ||
$this->save_cache(); | ||
return $this; | ||
} | ||
|
||
public function cache_nonce($nonce) { | ||
$this->cache['nonce'][$nonce] = true; | ||
$this->save_cache(); | ||
return $this; | ||
} | ||
|
||
public function check_nonce($nonce) { | ||
$this->load_cache(); | ||
if (!isset($this->cache['nonce'][$nonce])) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
private function load_cache() { | ||
$cache = file_get_contents(sys_get_temp_dir() . '/lti_cache.txt'); | ||
if (empty($cache)) { | ||
file_put_contents(sys_get_temp_dir() . '/lti_cache.txt', '{}'); | ||
$this->cache = []; | ||
} | ||
$this->cache = json_decode($cache, true); | ||
} | ||
|
||
private function save_cache() { | ||
file_put_contents(sys_get_temp_dir() . '/lti_cache.txt', json_encode($this->cache)); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
namespace IMSGlobal\LTI; | ||
|
||
class ImsCookie { | ||
public function get_cookie($name) { | ||
if (isset($_COOKIE[$name])) { | ||
return $_COOKIE[$name]; | ||
} | ||
// Look for backup cookie if same site is not supported by the user's browser. | ||
if (isset($_COOKIE["LEGACY_" . $name])) { | ||
return $_COOKIE["LEGACY_" . $name]; | ||
} | ||
return false; | ||
} | ||
|
||
public function set_cookie($name, $value, $exp = 3600, $options = []) { | ||
$cookie_options = [ | ||
'expires' => time() + $exp | ||
]; | ||
|
||
// SameSite none and secure will be required for tools to work inside iframes | ||
$same_site_options = [ | ||
'samesite' => 'None', | ||
'secure' => true | ||
]; | ||
|
||
setcookie($name, $value, array_merge($cookie_options, $same_site_options, $options)); | ||
|
||
// Set a second fallback cookie in the event that "SameSite" is not supported | ||
setcookie("LEGACY_" . $name, $value, array_merge($cookie_options, $options)); | ||
return $this; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
namespace IMSGlobal\LTI; | ||
|
||
class LTI_Constants | ||
{ | ||
public const V1_3 = '1.3.0'; | ||
|
||
// Required message claims | ||
public const MESSAGE_TYPE = 'https://purl.imsglobal.org/spec/lti/claim/message_type'; | ||
public const VERSION = 'https://purl.imsglobal.org/spec/lti/claim/version'; | ||
public const DEPLOYMENT_ID = 'https://purl.imsglobal.org/spec/lti/claim/deployment_id'; | ||
public const TARGET_LINK_URI = 'https://purl.imsglobal.org/spec/lti/claim/target_link_uri'; | ||
public const RESOURCE_LINK = 'https://purl.imsglobal.org/spec/lti/claim/resource_link'; | ||
public const ROLES = 'https://purl.imsglobal.org/spec/lti/claim/roles'; | ||
|
||
// Optional message claims | ||
public const CONTEXT = 'https://purl.imsglobal.org/spec/lti/claim/context'; | ||
public const TOOL_PLATFORM = 'https://purl.imsglobal.org/spec/lti/claim/tool_platform'; | ||
public const ROLE_SCOPE_MENTOR = 'https://purlimsglobal.org/spec/lti/claim/role_scope_mentor'; | ||
public const LAUNCH_PRESENTATION = 'https://purl.imsglobal.org/spec/lti/claim/launch_presentation'; | ||
public const LIS = 'https://purl.imsglobal.org/spec/lti/claim/lis'; | ||
public const CUSTOM = 'https://purl.imsglobal.org/spec/lti/claim/custom'; | ||
|
||
// LTI DL | ||
public const DL_CONTENT_ITEMS = 'https://purl.imsglobal.org/spec/lti-dl/claim/content_items'; | ||
public const DL_DATA = 'https://purl.imsglobal.org/spec/lti-dl/claim/data'; | ||
public const DL_DEEP_LINK_SETTINGS = 'https://purl.imsglobal.org/spec/lti-dl/claim/deep_linking_settings'; | ||
|
||
// LTI NRPS | ||
public const NRPS_CLAIM_SERVICE = 'https://purl.imsglobal.org/spec/lti-nrps/claim/namesroleservice'; | ||
public const NRPS_SCOPE_MEMBERSHIP_READONLY = 'https://purl.imsglobal.org/spec/lti-nrps/scope/contextmembership.readonly'; | ||
|
||
// LTI AGS | ||
public const AGS_CLAIM_ENDPOINT = 'https://purl.imsglobal.org/spec/lti-ags/claim/endpoint'; | ||
public const AGS_SCOPE_LINEITEM = 'https://purl.imsglobal.org/spec/lti-ags/scope/lineitem'; | ||
public const AGS_SCOPE_LINEITEM_READONLY = 'https://purl.imsglobal.org/spec/lti-ags/scope/lineitem.readonly'; | ||
public const AGS_SCOPE_RESULT_READONLY = 'https://purl.imsglobal.org/spec/lti-ags/scope/result.readonly'; | ||
public const AGS_SCOPE_SCORE = 'https://purl.imsglobal.org/spec/lti-ags/scope/score'; | ||
|
||
// User Vocab | ||
public const SYSTEM_ADMINISTRATOR = 'http://purl.imsglobal.org/vocab/lis/v2/system/person#Administrator'; | ||
public const SYSTEM_NONE = 'http://purl.imsglobal.org/vocab/lis/v2/system/person#None'; | ||
public const SYSTEM_ACCOUNTADMIN = 'http://purl.imsglobal.org/vocab/lis/v2/system/person#AccountAdmin'; | ||
public const SYSTEM_CREATOR = 'http://purl.imsglobal.org/vocab/lis/v2/system/person#Creator'; | ||
public const SYSTEM_SYSADMIN = 'http://purl.imsglobal.org/vocab/lis/v2/system/person#SysAdmin'; | ||
public const SYSTEM_SYSSUPPORT = 'http://purl.imsglobal.org/vocab/lis/v2/system/person#SysSupport'; | ||
public const SYSTEM_USER = 'http://purl.imsglobal.org/vocab/lis/v2/system/person#User'; | ||
public const INSTITUTION_ADMINISTRATOR = 'http://purl.imsglobal.org/vocab/lis/v2/institution/person#Administrator'; | ||
public const INSTITUTION_FACULTY = 'http://purl.imsglobal.org/vocab/lis/v2/institution/person#Faculty'; | ||
public const INSTITUTION_GUEST = 'http://purl.imsglobal.org/vocab/lis/v2/institution/person#Guest'; | ||
public const INSTITUTION_NONE = 'http://purl.imsglobal.org/vocab/lis/v2/institution/person#None'; | ||
public const INSTITUTION_OTHER = 'http://purl.imsglobal.org/vocab/lis/v2/institution/person#Other'; | ||
public const INSTITUTION_STAFF = 'http://purl.imsglobal.org/vocab/lis/v2/institution/person#Staff'; | ||
public const INSTITUTION_STUDENT = 'http://purl.imsglobal.org/vocab/lis/v2/institution/person#Student'; | ||
public const INSTITUTION_ALUMNI = 'http://purl.imsglobal.org/vocab/lis/v2/institution/person#Alumni'; | ||
public const INSTITUTION_INSTRUCTOR = 'http://purl.imsglobal.org/vocab/lis/v2/institution/person#Instructor'; | ||
public const INSTITUTION_LEARNER = 'http://purl.imsglobal.org/vocab/lis/v2/institution/person#Learner'; | ||
public const INSTITUTION_MEMBER = 'http://purl.imsglobal.org/vocab/lis/v2/institution/person#Member'; | ||
public const INSTITUTION_MENTOR = 'http://purl.imsglobal.org/vocab/lis/v2/institution/person#Mentor'; | ||
public const INSTITUTION_OBSERVER = 'http://purl.imsglobal.org/vocab/lis/v2/institution/person#Observer'; | ||
public const INSTITUTION_PROSPECTIVESTUDENT = 'http://purl.imsglobal.org/vocab/lis/v2/institution/person#ProspectiveStudent'; | ||
public const MEMBERSHIP_ADMINISTRATOR = 'http://purl.imsglobal.org/vocab/lis/v2/membership#Administrator'; | ||
public const MEMBERSHIP_CONTENTDEVELOPER = 'http://purl.imsglobal.org/vocab/lis/v2/membership#ContentDeveloper'; | ||
public const MEMBERSHIP_INSTRUCTOR = 'http://purl.imsglobal.org/vocab/lis/v2/membership#Instructor'; | ||
public const MEMBERSHIP_LEARNER = 'http://purl.imsglobal.org/vocab/lis/v2/membership#Learner'; | ||
public const MEMBERSHIP_MENTOR = 'http://purl.imsglobal.org/vocab/lis/v2/membership#Mentor'; | ||
public const MEMBERSHIP_MANAGER = 'http://purl.imsglobal.org/vocab/lis/v2/membership#Manager'; | ||
public const MEMBERSHIP_MEMBER = 'http://purl.imsglobal.org/vocab/lis/v2/membership#Member'; | ||
public const MEMBERSHIP_OFFICER = 'http://purl.imsglobal.org/vocab/lis/v2/membership#Officer'; | ||
|
||
// Context Vocab | ||
public const COURSE_TEMPLATE = 'http://purl.imsglobal.org/vocab/lis/v2/course#CourseTemplate'; | ||
public const COURSE_OFFERING = 'http://purl.imsglobal.org/vocab/lis/v2/course#CourseOffering'; | ||
public const COURSE_SECTION = 'http://purl.imsglobal.org/vocab/lis/v2/course#CourseSection'; | ||
public const COURSE_GROUP = 'http://purl.imsglobal.org/vocab/lis/v2/course#Group'; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,4 +87,4 @@ public function to_array() { | |
return $resource; | ||
} | ||
} | ||
?> | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,4 +20,3 @@ public function set_deployment_id($deployment_id) { | |
|
||
} | ||
|
||
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,3 @@ | |
class LTI_Exception extends \Exception { | ||
|
||
} | ||
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,4 +103,3 @@ public function __toString() { | |
])); | ||
} | ||
} | ||
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,4 +105,3 @@ public function __toString() { | |
])); | ||
} | ||
} | ||
?> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is super neat and something i've been meaning to do for an age but never brought myself to do it, so thanks for that