Pass authorisation header to coreapi client

This commit is contained in:
Emmanouil Konstantinidis 2017-02-27 12:31:17 +00:00
parent c09ebe4622
commit 21536f3c3c
2 changed files with 22 additions and 5 deletions

View File

@ -68,6 +68,7 @@
}
return cookieValue;
}
const csrf = {'X-CSRFToken': getCookie('csrftoken')}
const coreapi = window.coreapi
@ -173,7 +174,18 @@
form.find(".response-raw-response").text(panelText)
}
const client = new coreapi.Client({csrf: csrf, requestCallback: requestCallback, responseCallback: responseCallback})
let options = {
requestCallback: requestCallback,
responseCallback: responseCallback,
}
if (window.auth && window.auth.type === 'token') {
options.headers = {
'Authorization': window.auth.value
}
}
const client = new coreapi.Client(options)
client.action(doc, key, params).then(function (data) {
var response = JSON.stringify(data, null, 2);
@ -205,15 +217,20 @@
$('form.authentication-form').submit(function(event) {
event.preventDefault();
const form = $(this).closest("form");
const token = window.token = form.find('input').val();
const value = form.find('input').val();
$('#auth_token_modal').modal('hide');
$('#auth-control').children().removeClass('active');
if (token) {
if (value) {
window.auth = {
'type': 'token',
'value': value,
};
$('#selected-authentication').text('token');
$('#auth-control').find("[data-auth='token']").addClass('active');
} else {
window.auth = null;
$('#selected-authentication').text('none');
$('#auth-control').find("[data-auth='none']").addClass('active');
}
@ -221,7 +238,7 @@
$('#auth-control').find("[data-auth='none']").click(function (event) {
event.preventDefault();
window.token = null;
window.auth = null;
$('#selected-authentication').text('none');
$('#auth-control').find("[data-auth='none']").addClass('active');
$('#auth-control').find("[data-auth='token']").removeClass('active');

View File

@ -20,7 +20,7 @@
<li data-toggle="collapse" data-target="#auth-control" class="collapsed">
<a><i class="fa fa-user fa-lg"></i> Authentication</a> <span id="selected-authentication">none</span>
</li>
<ul class="sub-menu out" id="auth-control">
<ul class="sub-menu collapse out" id="auth-control">
<li data-auth="none" class="active"><a href="#" data-language="none">none</a></li>
<li data-auth="token" data-toggle="modal" data-target="#auth_token_modal"><a href="#">token</a></li>
</ul>