Skip to content

Instantly share code, notes, and snippets.

@hirokiky
Created March 14, 2018 03:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hirokiky/fdd1b27bf68d00ecba5ae554bd666a0d to your computer and use it in GitHub Desktop.
Save hirokiky/fdd1b27bf68d00ecba5ae554bd666a0d to your computer and use it in GitHub Desktop.
tried to inject Authorization header for each request, but couldn't.
// This way didn't work.
// Cause this custom.js or nbextensions files will be loaded after initializing JupyterNotebookApp.
// It means this code won't affect to it's initializing Ajax requests.
// Sending token on each XHRs too.
// Because Safari won't handle Cookie and localStorage
// on iframes.
// Jupyter Client expects it's cookie, so it will be forbidden
// Instead, sending "token" by manually on each XHRs.
// Retrieving token from data attribute
// Because Jupyter Notebook will delete ?token param automatically.
var token = document.querySelector('body').dataset.jupyterApiToken || '';
jQuery.ajaxSetup({
headers: {"Authorization": 'token ' + token}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment