-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Added the security check page from docs to demos, currently
pointing at Questions API V1 until a fix is made to make it compatible with V2. https://app.asana.com/0/8825147419757/8855479765468
- Loading branch information
1 parent
87849e8
commit 72d1218
Showing
12 changed files
with
3,685 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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 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 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,157 @@ | ||
<?php include_once '../src/includes/header.php'; ?> | ||
|
||
<div class="jumbotron"> | ||
<h1>Security Check</h1> | ||
<p>This is a simple security test that attempts to make a request to the Questions API, | ||
passing the security parameters you provide in the form below.</p> | ||
<p>If the request is successful, a status code 200 will be returned in the box at the | ||
bottom of the page, otherwise a status code 403 will be returned.</p> | ||
<p>Information on security is available on the documentation site for | ||
the <a href="http://docs.learnosity.com/questionsapi/apiauth.php">Questions API</a>.</p> | ||
</div> | ||
|
||
<form id="securityForm"> | ||
<fieldset> | ||
<div class="row"> | ||
<div class="col-lg-6"> | ||
<h2>Security Parameters</h2> | ||
<label for="consumer_key">consumer_key:</label> | ||
<div class="form-group"> | ||
<div class="row"> | ||
<div class="col-xs-4"> | ||
<input type="text" id="consumer_key" name="consumer_key" value="" class="signaturePart form-control"> | ||
</div> | ||
</div> | ||
<div class="help-block"> | ||
Unique id provided by Learnosity that allows the server to identify the | ||
client and retrive its <em>consumer_secret</em>. | ||
</div> | ||
</div> | ||
|
||
<label for="domain">domain:</label> | ||
<div class="form-group"> | ||
<div class="row"> | ||
<div class="col-xs-6"> | ||
<input type="text" id="domain" name="domain" value="" class=" signaturePart form-control"> | ||
</div> | ||
</div> | ||
<div class="help-block"> | ||
Must be the same as <em>location.hostname</em>, as the Learnosity Questions API is sending | ||
that value to the server for authentication. | ||
</div> | ||
</div> | ||
|
||
<label for="timestamp">timestamp:</label> | ||
<div class="form-group"> | ||
<div class="row"> | ||
<div class="col-xs-4"> | ||
<input type="text" id="timestamp" name="timestamp" value="" class="span4 signaturePart form-control"> | ||
</div> | ||
</div> | ||
<div class="help-block"> | ||
Current time in GMT/UTC.The server will check if the timestamp is within the allowed | ||
time frame: 3h in this test. | ||
</div> | ||
</div> | ||
|
||
<label for="user_id">user_id:</label> | ||
<div class="form-group"> | ||
<div class="row"> | ||
<div class="col-xs-4"> | ||
<input type="text" id="user_id" name="user_id" value="" class="span4 signaturePart form-control"> | ||
</div> | ||
</div> | ||
<div class="help-block">The id of the student/user whose assets are to be requested.</div> | ||
</div> | ||
|
||
<label for="consumer_secret">consumer_secret:</label> | ||
<div class="form-group"> | ||
<div class="row"> | ||
<div class="col-xs-8"> | ||
<input type="text" id="consumer_secret" name="consumer_secret" value="" class="signaturePart form-control"> | ||
</div> | ||
</div> | ||
<div class="help-block"> | ||
Secret key supplied by Learnosity, which <strong>must not be exposed</strong> | ||
either by sending it to the browser or across the network. | ||
</div> | ||
</div> | ||
</div> | ||
<div class="col-lg-6"> | ||
<div class="form-group"> | ||
<h3>Sample Activity JSON object</h3> | ||
<pre id="actJson" class="cm-s-elegant"></pre> | ||
</div> | ||
<label for="domain"><strong>domain override:</strong></label> | ||
<div class="form-group"> | ||
<input type="text" id="domain_override" name="domain" value="" class="signaturePart form-control"> | ||
</div> | ||
<span class="help-block"> | ||
Override the <em>window.location</em> comparison. This domain must be registered | ||
with Learnosity against the <em>consumer_key</em> being used. | ||
</span> | ||
</div> | ||
</div> | ||
|
||
<hr> | ||
|
||
<div class="row"> | ||
<div class="col-lg-12"> | ||
<label for="signature">concatenated string:</label> | ||
<div class="input"> | ||
<pre id="concatenation"></pre> | ||
<span class="help-block"> | ||
Concatenation of the above parameters in order, separated by underscores. | ||
</span> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<hr> | ||
|
||
<div class="row"> | ||
<div class="col-lg-12"> | ||
<label for="signature">signature:</label> | ||
<div class="form-group"> | ||
<input type="text" id="signature" name="signature" value="" class="col-lg-12 form-control"> | ||
<span class="help-block"> | ||
64 character long string, resulting from applying the SHA256 hashing algorithm | ||
to the concatenated string. | ||
</span> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<hr> | ||
|
||
<div class="col-lg-12"> | ||
<button class="btn btn-primary" id="testbtn">Test</button> | ||
<button class="btn btn-default" id="resetbtn">Reset to Defaults</button> | ||
</div> | ||
|
||
<hr> | ||
|
||
<div class="row"> | ||
<div class="col-lg-12"> | ||
<h3>Server Response</h3> | ||
<pre id="serverresponse"></pre> | ||
</div> | ||
</div> | ||
</fieldset> | ||
</form> | ||
|
||
<script src="/static/vendor/require/require.js"></script> | ||
<script> | ||
var LearnosityAmd = {}; | ||
LearnosityAmd.requirejs = requirejs; | ||
LearnosityAmd.require = require; | ||
LearnosityAmd.define = define; | ||
var timestamp = '<?php echo gmdate('Ymd-Hi'); ?>'; | ||
</script> | ||
<script src="/static/vendor/sha256.js"></script> | ||
<script src="/static/js/securityCheck.js"></script> | ||
<script src="/static/vendor/underscore.min.js"></script> | ||
<script src="/static/vendor/codemirror/codemirror.min.js"></script> | ||
<script src="/static/vendor/beautify.js"></script> | ||
|
||
<?php include_once '../src/includes/footer.php'; |
This file contains 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 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,156 @@ | ||
/*global $, require, jsSHA, window, LearnosityApp, _, CodeMirror, js_beautify */ | ||
$(function () { | ||
"use strict"; | ||
var concatenated = "", | ||
activityTemplate = 'var activity = {"consumer_key":"<%= act.consumer_key %>","timestamp":"<%= act.timestamp %>","signature":"<%= act.signature %>","user_id":"<%= act.user_id %>", ... };', | ||
defaults = { | ||
consumer_key: 'soCnIErF4fojFiKe', | ||
domain: location.hostname, | ||
timestamp: window.timestamp, | ||
user_id: '12345678', | ||
consumer_secret: '457e0592c9a63b9d6cd39966c49db45c7ceee784' | ||
}, | ||
domain = "api.learnosity.com", | ||
LearnosityApp = {}, | ||
questionsApiComms; | ||
|
||
function initialiseQuestionsAPI() { | ||
LearnosityApp._internal = {}; | ||
LearnosityApp._internal.config = { | ||
apiHost: 'http://' + domain + "/stable" | ||
}; | ||
window.LearnosityApp = LearnosityApp; | ||
|
||
var apiModules = '//' + domain + '/stable/scripts'; | ||
require.config({ | ||
baseUrl: apiModules | ||
}); | ||
require(['comms'], function (comms) { | ||
questionsApiComms = comms; | ||
}); | ||
} | ||
|
||
function updateActJsonArea() { | ||
var actText = _.template(activityTemplate, { act: { | ||
consumer_key: $('#consumer_key').val(), | ||
timestamp: $('#timestamp').val(), | ||
user_id: $('#user_id').val(), | ||
signature: $('#signature').val() | ||
} }); | ||
CodeMirror.runMode(js_beautify(actText), {name: "javascript", json: true}, $('#actJson')[0]); | ||
} | ||
|
||
function loadDefaults() { | ||
$('#consumer_key').val(defaults.consumer_key); | ||
$('#domain').val(defaults.domain); | ||
$('#domain_override').val(defaults.domain); | ||
$('#timestamp').val(defaults.timestamp); | ||
$('#user_id').val(defaults.user_id); | ||
$('#consumer_secret').val(defaults.consumer_secret); | ||
$('#signature').val(''); | ||
$('#serverresponse').html(''); | ||
} | ||
|
||
function concatenateStringAndGenerateSignature() { | ||
concatenated = ""; | ||
concatenated += $('#consumer_key').val(); | ||
concatenated += '_'; | ||
concatenated += $('#domain_override').val(); | ||
concatenated += '_'; | ||
concatenated += $('#timestamp').val(); | ||
concatenated += '_'; | ||
concatenated += $('#user_id').val(); | ||
concatenated += '_'; | ||
concatenated += $('#consumer_secret').val(); | ||
|
||
var conc = ""; | ||
conc += '<span title="consumer_key" class="conpart">' + $('#consumer_key').val() + '</span>'; | ||
conc += '<strong>_</strong>'; | ||
conc += '<span title="domain" class="conpart2">' + $('#domain_override').val() + '</span>'; | ||
conc += '<strong>_</strong>'; | ||
conc += '<span title="timestamp" class="conpart">' + $('#timestamp').val() + '</span>'; | ||
conc += '<strong>_</strong>'; | ||
conc += '<span title="user_id" class="conpart2">' + $('#user_id').val() + '</span>'; | ||
conc += '<strong>_</strong>'; | ||
conc += '<span title="consumer_secret" class="conpart">' + $('#consumer_secret').val() + '</span>'; | ||
|
||
$('#concatenation').html(conc); | ||
|
||
var shaObj = new jsSHA(concatenated); | ||
$('#signature').val(shaObj.getHash("SHA-256", "HEX")); | ||
} | ||
|
||
function testSuccess(response) { | ||
$('#serverresponse').html(response.status); | ||
} | ||
|
||
function testError(response) { | ||
$('#serverresponse').html(response.status + ' - ' + response.response); | ||
} | ||
|
||
function submitToServer(withSecurity) { | ||
$('#serverresponse').html(''); | ||
var secParams = { | ||
consumer_key: $('#consumer_key').val(), | ||
domain: $('#domain_override').val(), | ||
timestamp: $('#timestamp').val(), | ||
user_id: $('#user_id').val(), | ||
signature: $('#signature').val() | ||
}; | ||
if (questionsApiComms) { | ||
questionsApiComms.request({ | ||
url: '/authenticate', | ||
security: { | ||
security: JSON.stringify({ | ||
consumer_key: secParams.consumer_key, | ||
domain: secParams.domain, | ||
timestamp: secParams.timestamp, | ||
user_id: secParams.user_id, | ||
signature: secParams.signature | ||
}) | ||
}, | ||
success: testSuccess, | ||
failure: testError | ||
}); | ||
} | ||
} | ||
|
||
|
||
$('form').on('submit', function (e) { | ||
e.preventDefault(); | ||
}); | ||
|
||
$('#domain').val(location.hostname); | ||
|
||
$(':text').keypress(function (e) { | ||
if (e.keyCode == 13) { | ||
e.preventDefault(); | ||
$(this).blur(); | ||
} | ||
}); | ||
|
||
$('.signaturePart').change(function () { | ||
concatenateStringAndGenerateSignature(); | ||
updateActJsonArea(); | ||
}); | ||
|
||
$('#signature').change(function () { | ||
updateActJsonArea(); | ||
}); | ||
|
||
|
||
$('#resetbtn').click(function () { | ||
loadDefaults(); | ||
concatenateStringAndGenerateSignature(); | ||
updateActJsonArea(); | ||
}); | ||
|
||
$('#testbtn').click(function () { | ||
submitToServer(true); | ||
}); | ||
|
||
initialiseQuestionsAPI(); | ||
loadDefaults(); | ||
concatenateStringAndGenerateSignature(); | ||
updateActJsonArea(); | ||
}); |
Oops, something went wrong.