Skip to content

Commit

Permalink
Merge pull request #7 from bfidatadigipres/feat/with-credentials
Browse files Browse the repository at this point in the history
Allows credentials (i.e. cookies) to be sent with manifest and image requests
  • Loading branch information
danielgrant authored Apr 7, 2021
2 parents dde5abe + c1bcf1d commit 3b7ae75
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<div id="uv" class="uv"></div>
</div>

<script type="text/javascript" src="index.js"></script>
<script type="text/javascript" src="uv/uv.js"></script>
<script type="text/javascript" src="index.js"></script>
</body>
</html>
32 changes: 31 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
var uv;

$.ajaxSetup({
xhrFields: {
withCredentials: true
},
beforeSend: function(jqXHR, settings) {
jqXHR.requestUrl = settings.url
},
error: function(jqXHR, textStatus, errorThrown) {
console.error('Got [' + errorThrown + '] logging request [' + jqXHR.requestUrl + ']');
logout();
}
})

requirejs.onResourceLoad = function (context, map, depArray) {
if (map.name === 'lib/manifesto.js') {
const originalLoad = window.Manifesto.loadManifest;
window.Manifesto.Utils.loadResource = window.Manifesto.loadManifest = function (url) {
return axios.get(url, {
withCredentials: true,
validateStatus: status => status === 200 || status === 204
}).then(function(r) {
return r.data;
}).catch(function (error) {
console.error('Got [' + JSON.stringify(error) + '] logging request [' + url + ']');
logout();
});
};
}
}

window.addEventListener('uvLoaded', function (e) {

var manifest = Utils.Urls.getHashParameter('manifest');
Expand Down Expand Up @@ -63,7 +93,7 @@ function logEvent(type, payload) {
'Content-Type': 'application/json',
},
validateStatus: status => status === 200 || status === 204
}).catch(error => {
}).catch(function (error) {
console.error('Got [' + JSON.stringify(error) + '] logging event [' + JSON.stringify(payload) + ']');
logout();
});
Expand Down

0 comments on commit 3b7ae75

Please sign in to comment.