Skip to content

Commit

Permalink
update token strings and api targets
Browse files Browse the repository at this point in the history
  • Loading branch information
thostetler committed Jan 30, 2024
1 parent e05b5f2 commit 4909ab5
Show file tree
Hide file tree
Showing 8 changed files with 546 additions and 538 deletions.
62 changes: 31 additions & 31 deletions src/js/apps/bumblebox/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ define([
'js/components/api_query',
'js/components/api_request',
'js/components/pubsub_events',
], function(_, $, Backbone, ApiQuery, ApiRequest, PubSubEvents) {
], function (_, $, Backbone, ApiQuery, ApiRequest, PubSubEvents) {
var Mixin = {
/**
* Happens first, when the application starts (but before it starts
* loading modules). Here is the time to retrieve whatever configuration
* and/or files that should be available to the app instance
*/
bootstrap: function(conf) {
bootstrap: function (conf) {
conf = conf || {};
var defer = $.Deferred();

Expand All @@ -26,7 +26,7 @@ define([

// harvest information from the remote urls and merge it into one object
var reqs = [];
_.each(conf.bootstrapUrls, function(url) {
_.each(conf.bootstrapUrls, function (url) {
if (!url) return;
if (url.indexOf('.json') > -1) {
var jqXhr = $.ajax({
Expand All @@ -36,7 +36,7 @@ define([
contentType: 'application/x-www-form-urlencoded',
cache: false,
timeout: 3000,
success: function(data) {
success: function (data) {
if (_.isString(data)) {
var v = eval(data);
if (_.isFunction(v)) {
Expand All @@ -50,23 +50,23 @@ define([
});
} else {
jqXhr = $.Deferred();
require([url], function(data) {
require([url], function (data) {
_.extend(retVal, data);
jqXhr.resolve();
}, function() {
}, function () {
jqXhr.resolve();
});
}
reqs.push(jqXhr);
});
if (reqs.length > 0) {
$.when.apply($, reqs).then(
function() {
function () {
defer.resolve(retVal);
},
function() {
function () {
defer.reject(arguments);
}
},
);
} else {
defer.resolve({});
Expand All @@ -85,7 +85,7 @@ define([
* @param dynamic_config
* @returns {*}
*/
onBootstrap: function(app_config, dynamic_config) {
onBootstrap: function (app_config, dynamic_config) {
// this is little bit of a (necessary) hack, we'll
// update the configuration of the requirejs's
var rConfig = null;
Expand All @@ -103,11 +103,11 @@ define([
rConfig = kontext.config;
}
}
var enhanceConfig = function(targetConfig, dynamic_config) {
_.each(dynamic_config, function(value, key, obj) {
var enhanceConfig = function (targetConfig, dynamic_config) {
_.each(dynamic_config, function (value, key, obj) {
if (targetConfig[key]) {
var target = rConfig[key];
_.each(value, function(value, key, obj) {
_.each(value, function (value, key, obj) {
target[key] = _.defaults(value, target[key]); // use the new values as defaults
});
}
Expand All @@ -129,7 +129,7 @@ define([
*
* @param loadedConfig
*/
configure: function(loadedConfig) {
configure: function (loadedConfig) {
var conf = this.getObject('DynamicConfig') || {};
conf = _.extend(conf, loadedConfig);

Expand All @@ -153,14 +153,14 @@ define([
}

this.getBeeHive()
.getService('Api')
.setVals({
access_token: 'Bearer:' + conf.access_token,
refresh_token: conf.refresh_token, // will probably be null....
expires_in: conf.expires_in,
clientVersion: null, // to avoid sending the headers (for now)
defaultTimeoutInMs: conf.defaultTimeoutInMs || 15000,
});
.getService('Api')
.setVals({
access_token: `Bearer ${conf.access_token}`,
refresh_token: conf.refresh_token, // will probably be null....
expires_in: conf.expires_in,
clientVersion: null, // to avoid sending the headers (for now)
defaultTimeoutInMs: conf.defaultTimeoutInMs || 15000,
});

// set the API key and other data from bootstrap
if (conf.access_token) {
Expand All @@ -170,27 +170,27 @@ define([
}
},

reload: function(endPage) {
reload: function (endPage) {
throw new Error('Should never be called by an embedded app.');
},

redirect: function(endPage) {
redirect: function (endPage) {
throw new Error('Should never be called by an embedded app.');
},

start: function(Router) {
start: function (Router) {
var app = this;
var beehive = this.getBeeHive();
var api = beehive.getService('Api');
var conf = this.getObject('DynamicConfig');

this.getBeeHive()
.getObject('AppStorage')
.setConfig(conf);
.getObject('AppStorage')
.setConfig(conf);

var complain = function(x) {
var complain = function (x) {
throw new Error(
'Ooops. Check your config! There is no ' + x + ' component @#!'
'Ooops. Check your config! There is no ' + x + ' component @#!',
);
};

Expand All @@ -205,8 +205,8 @@ define([

// attach the master page to the body
$(conf.targetElement || 'div#body-template-container')
.empty()
.append(masterPageManager.view.el);
.empty()
.append(masterPageManager.view.el);

// kick off routing
app.router = new Router();
Expand Down
6 changes: 4 additions & 2 deletions src/js/components/api_targets.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* and any related limits
*/

define([], function() {
define([], function () {
var config = {
BOOTSTRAP: '/accounts/bootstrap',
SEARCH: 'search/query',
Expand All @@ -31,13 +31,15 @@ define([], function() {
USER_DATA: 'vault/user-data',
SITE_CONFIGURATION: 'vault/configuration',
TOKEN: 'accounts/token',
LOGIN: 'accounts/login',
LOGOUT: 'accounts/logout',
REGISTER: 'accounts/register',
VERIFY: 'accounts/verify',
DELETE: 'accounts/user/delete',
DELETE: 'accounts/delete',
RESET_PASSWORD: 'accounts/reset-password',
CHANGE_PASSWORD: 'accounts/change-password',
CHANGE_EMAIL: 'accounts/change-email',
INFO: 'accounts/info',

RECOMMENDER: 'recommender',
GRAPHICS: 'graphics',
Expand Down
2 changes: 1 addition & 1 deletion src/js/widgets/user_settings/templates/api_key.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<br/>
<p> This API token allows you to access ADS data programmatically. For instance, to fetch the first few bibcodes for the query "star", make the following request: </p>
<p>
<code> curl -H 'Authorization: Bearer:{{#if access_token}}{{access_token}}{{else}}[YOUR TOKEN HERE]{{/if}}' 'https://api.adsabs.harvard.edu/v1/search/query?q=star&fl=bibcode'</code>
<code> curl -H 'Authorization: Bearer {{#if access_token}}{{access_token}}{{else}}[YOUR TOKEN HERE]{{/if}}' 'https://api.adsabs.harvard.edu/v1/search/query?q=star&fl=bibcode'</code>
</p>
<p>
<i>(If you've generated a token, you can copy-paste the preceding line directly into your terminal)</i>
Expand Down

0 comments on commit 4909ab5

Please sign in to comment.