/** * // Avoid server side code : // https://github.com/ipython/ipython/issues/2780 * * This essentially boils down to the following: * Github authentication requires some server-side code for any 'app' which * wants to authenticate over the Github API. * When registering an app with Github, Github provides the app with what they * call a 'client secret'. * The client secret is then incorporated into the app, and the app sends it to * Github as part of the authentication process, thus proving to Github's * servers that the communicating app was written by someone with appropriate * credentials. * * The issue with writing a single Github app for Gist-ing notebooks, is that * it would need to include such a client secret. Since this would be part of * the extension source code, anyone could use the client secret, potentially * gaining the permissions that any given user has granted to the app. * * As a result, we only support: * - anonymous (non-authenticated) API usage * - client-side authentication using a personal access token * (see https://github.com/settings/tokens) */ define([ 'jquery', 'base/js/namespace', 'base/js/dialog' ], function ( $, Jupyter, dialog ) { "use strict"; // define default values for config parameters var params = { gist_it_default_to_public: false, gist_it_personal_access_token: '', github_endpoint: 'github.com' }; var initialize = function () { update_params(); Jupyter.toolbar.add_buttons_group([ Jupyter.keyboard_manager.actions.register ({ help : 'Create/Edit Gist of Notebook', icon : 'fa-github', handler: show_gist_editor_modal }, 'create-gist-from-notebook', 'gist_it') ]); }; // update params with any specified in the server's config file var update_params = function() { var config = Jupyter.notebook.config; for (var key in params) { if (config.data.hasOwnProperty(key)) params[key] = config.data[key]; } default_metadata.data.public = Boolean(config.data.gist_it_default_to_public); }; var default_metadata = { id: '', data: { description: Jupyter.notebook.notebook_path, public: false } }; function ensure_default_metadata () { Jupyter.notebook.metadata.gist = $.extend( true, // deep-copy default_metadata, //defaults Jupyter.notebook.metadata.gist // overrides ); } var add_auth_token = function add_auth_token (xhr) { var token = ''; if (params.gist_it_personal_access_token !== '') { token = params.gist_it_personal_access_token; } if (token !== '') { xhr.setRequestHeader("Authorization", "token " + token); } }; function build_alert(alert_class) { return $('
') .addClass('alert alert-dismissable') .addClass(alert_class) .append( $('