diff --git a/src/controllers/auth.js b/src/controllers/auth.js index 462cf4ac59..dd508039ad 100644 --- a/src/controllers/auth.js +++ b/src/controllers/auth.js @@ -20,9 +20,8 @@ var NO_SESSION_FOUND = { err: "You must be logged in." }; */ api.auth = function(req, res, next) { - var token, uid; - uid = req.headers['x-api-user']; - token = req.headers['x-api-key']; + var uid = req.headers['x-api-user']; + var token = req.headers['x-api-key']; if (!(uid && token)) return res.json(401, NO_TOKEN_OR_UID); User.findOne({_id: uid,apiToken: token}, function(err, user) { if (err) return res.json(500, {err: err}); diff --git a/src/routes/apiv2.coffee b/src/routes/apiv2.coffee index a6f16fd68e..e33a68b4e5 100644 --- a/src/routes/apiv2.coffee +++ b/src/routes/apiv2.coffee @@ -518,7 +518,7 @@ module.exports = (swagger, v2) -> #type: 'Pet' errorResponses: [] method: 'GET' - middleware: if path.indexOf('/user') is 0 then [auth.auth, cron] else [] + route.middleware ?= if path.indexOf('/user') is 0 then [auth.auth, cron] else [] swagger["add#{route.spec.method}"](route);true diff --git a/views/static/api.jade b/views/static/api.jade index e833694f4c..df1a73fad4 100644 --- a/views/static/api.jade +++ b/views/static/api.jade @@ -19,30 +19,40 @@ html script(type='text/javascript') $(function () { window.swaggerUi = new SwaggerUi({ - url: "/api/v2/api-docs", - dom_id: "swagger-ui-container", - supportedSubmitMethods: ['get', 'post', 'put', 'delete'], - onComplete: function(swaggerApi, swaggerUi){ - if(console) { - console.log("Loaded SwaggerUI") - } - $('pre code').each(function(i, e) {hljs.highlightBlock(e)}); - }, - onFailure: function(data) { - if(console) { - console.log("Unable to Load SwaggerUI"); - console.log(data); - } - }, - docExpansion: "none" + url: "/api/v2/api-docs", + dom_id: "swagger-ui-container", + supportedSubmitMethods: ['get', 'post', 'put', 'delete'], + onComplete: function(swaggerApi, swaggerUi){ + if(console) { + console.log("Loaded SwaggerUI") + } + $('pre code').each(function(i, e) {hljs.highlightBlock(e)}); + }, + onFailure: function(data) { + if(console) { + console.log("Unable to Load SwaggerUI"); + console.log(data); + } + }, + docExpansion: "none" }); + debugger; + $('#input_apiKey').change(function() { var key = $('#input_apiKey')[0].value; - console.log("key: " + key); + console.log("apiKey: " + key); if(key && key.trim() != "") { console.log("added key " + key); - window.authorizations.add("key", new ApiKeyAuthorization("api_key", key, "query")); + window.authorizations.add("apiKey", new ApiKeyAuthorization("x-api-key", key, "header")); + } + }) + $('#input_uuid').change(function() { + var key = $('#input_uuid')[0].value; + console.log("uuid: " + key); + if(key && key.trim() != "") { + console.log("added key " + key); + window.authorizations.add("uuid", new ApiKeyAuthorization("x-api-user", key, "header")); } }) window.swaggerUi.load(); @@ -51,22 +61,16 @@ html #header .swagger-ui-wrap a#logo(href='http://swagger.wordnik.com') HabitRPG API Documentation (Under Construction) - //-form#api_selector - //- -
- -
-
- -
- .input - input#input_baseUrl(placeholder='http://example.com/api', name='baseUrl', type='text') - .input - input#input_apiKey(placeholder='api_key', name='apiKey', type='text') - .input - a#explore(href='#') Explore .swagger-ui-wrap(style='padding:50px') + form#api_selector + .input + input#input_uuid(placeholder='UUID', name='uuid', type='text') + input#input_apiKey(placeholder='API Key', name='apiKey', type='text') + //.input + input#input_baseUrl(placeholder='http://example.com/api', name='baseUrl', type='text') + //.input + a#explore(href='#') Explore p(style='color:red') This documentation is a work in progress. If you'd like to help finish it, see #2217. #message-bar.swagger-ui-wrap