Skip to content

Commit

Permalink
display token with curl command
Browse files Browse the repository at this point in the history
  • Loading branch information
c0ze committed Jan 27, 2018
1 parent 435954f commit 9c00934
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
19 changes: 17 additions & 2 deletions client/components/FnRunFunction.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@
<div class="form-group">
<label class="col-sm-3 control-label">Payload</label>
<div class="col-sm-9">
<textarea class="form-control" v-model="payload" placeholder="e.g. {}"></textarea>
<textarea class="form-control" v-model="payload" placeholder="e.g. {}" v-on:change="calculateToken"></textarea>
</div>
</div>
<div>
<div v-if="!route.jwt_key">
<h5>cURL command</h5>
<pre>curl -X POST -d '{{payload}}' {{apiUrl}}r/{{encodeURIComponent(this.app.name)}}/{{encodeURIComponent(this.route.path)}}</pre>
</div>
<div v-if="route.jwt_key">
<h5>cURL command</h5>
<pre>curl -X POST -H 'Authorization: Bearer {{authToken}}' -d '{{payload}}' {{apiUrl}}r/{{encodeURIComponent(this.app.name)}}/{{encodeURIComponent(this.route.path)}}</pre>
</div>

<div v-show="output">
<h5>Output</h5>
Expand All @@ -46,6 +50,7 @@
import Modal from '../lib/VueBootstrapModal.vue';
import { eventBus } from '../client';
import { defaultErrorHandler, getApiUrl } from '../lib/helpers';
const jwt = require('jsonwebtoken');
export default {
props: ['app'],
Expand All @@ -58,6 +63,7 @@ export default {
show: false,
submitting: false,
payload: '{}',
authToken: null,
output: null,
apiUrl: ''
}
Expand Down Expand Up @@ -93,6 +99,9 @@ export default {
}
})
},
calculateToken: function() {
this.authToken = jwt.sign(this.payload, this.route.jwt_key);
},
},
created: function (){
var t = this;
Expand All @@ -101,6 +110,12 @@ export default {
this.payload = '{}';
this.output = null;
this.show = true;
if(this.route.jwt_key) {
this.calculateToken();
}
});
eventBus.$on('calculateToken', () => {
this.calculateToken();
});
getApiUrl( url => t.apiUrl = url );
}
Expand Down
9 changes: 7 additions & 2 deletions server/controllers/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,13 @@ router.post('/:app/routes/:route/run', function(req, res) {
res.status(400).json({msg: text});
}
var data = req.body.payload;
var token = jwt.sign(data, req.headers['x-jwt-key']);
var authHeader = {'Authorization': 'Bearer ' + token };
if (req.headers['x-jwt-key']) {
var token = jwt.sign(data, req.headers['x-jwt-key']);
var authHeader = {'Authorization': 'Bearer ' + token };
}
else {
var authHeader = {};
}
var path = "/r/" + encodeURIComponent(req.params.app)+ "/" + encodeURIComponent(req.params.route);
helpers.execApiEndpointRaw('POST', req, path, {}, data, successcb, errcb, authHeader);

Expand Down

0 comments on commit 9c00934

Please sign in to comment.