Skip to content

Commit

Permalink
Feat/no auth (#41)
Browse files Browse the repository at this point in the history
* Feature to allow publishing of an api without having to require any authentication.

* Don't show application related message for no-auth API

* Fixed issue Haufe-Lexware/wicked.haufe.io#177

* Fixed Haufe-Lexware/wicked.haufe.io#179
  • Loading branch information
santokhsingh authored and DonMartin76 committed Apr 1, 2019
1 parent 3a6012a commit da96755
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
17 changes: 14 additions & 3 deletions routes/apis.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const marked = require('marked');
const markedOptions = utils.markedOptions;
const async = require('async');
const cors = require('cors');
const mustache = require('mustache');
const wicked = require('wicked-sdk');

router.get('/', function (req, res, next) {
Expand Down Expand Up @@ -80,6 +79,18 @@ function unique(arr) {
return a;
}

function deduceHostAndSchema(req, apiConfig) {
const nw = req.app.portalGlobals.network;
const host = (apiConfig.api.host) ? apiConfig.api.host : nw.apiHost;
const ssl = (nw.schema == 'https') ? true : false;
let schema = nw.schema;
switch (apiConfig.api.protocol) {
case 'ws:':
case 'wss:':
schema = (ssl) ? 'wss' : 'ws';
}
return `${schema}://${host}`;
}

router.get('/:api', function (req, res, next) {
debug("get('/:api')");
Expand Down Expand Up @@ -149,10 +160,10 @@ router.get('/:api', function (req, res, next) {
// necessary configuration option for any API gateway.
// console.log(JSON.stringify(apiConfig));
const apiUris = [];
const nw = req.app.portalGlobals.network;
const host = deduceHostAndSchema(req, apiConfig);
for (let u = 0; u < apiConfig.api.uris.length; ++u) {
const apiRequestUri = apiConfig.api.uris[u];
apiUris.push(nw.schema + '://' + nw.apiHost + apiRequestUri);
apiUris.push(`${host}${apiRequestUri}`);
}

const plans = results.getPlans;
Expand Down
10 changes: 6 additions & 4 deletions views/api.jade
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,12 @@ block content
#apidescription.collapse.panel-collapse.in
.panel-body
!= apiDesc

a(href="#{glob.network.schema}://#{glob.network.apiHost}/swagger-ui/?url=#{encodeURIComponent(genericSwaggerUrl)}" role="button" target="_blank").btn.btn-default View Swagger definition &raquo;
if apiInfo.auth == "none"
a(href="#{glob.network.schema}://#{glob.network.apiHost}/swagger-ui/?apikey=none&url=#{encodeURIComponent(genericSwaggerUrl)}" role="button" target="_blank").btn.btn-default View Swagger definition &raquo;
else
a(href="#{glob.network.schema}://#{glob.network.apiHost}/swagger-ui/?url=#{encodeURIComponent(genericSwaggerUrl)}" role="button" target="_blank").btn.btn-default View Swagger definition &raquo;

if !authUser
if !authUser && apiInfo.auth != "none"
.panel.panel-danger
.panel-heading
h4.panel-title Not logged in
Expand All @@ -141,7 +143,7 @@ block content
p
a(href="/login?redirect=/apis/#{apiInfo.id}").btn.btn-default Log in &raquo;

else
else if apiInfo.auth != "none"
.panel.panel-default
.panel-heading
+panelTitle('Applications', '/help/api')
Expand Down

0 comments on commit da96755

Please sign in to comment.