mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-06 13:30:12 +03:00
Pass authorisation header to coreapi client
This commit is contained in:
parent
c09ebe4622
commit
21536f3c3c
|
@ -68,6 +68,7 @@
|
||||||
}
|
}
|
||||||
return cookieValue;
|
return cookieValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const csrf = {'X-CSRFToken': getCookie('csrftoken')}
|
const csrf = {'X-CSRFToken': getCookie('csrftoken')}
|
||||||
|
|
||||||
const coreapi = window.coreapi
|
const coreapi = window.coreapi
|
||||||
|
@ -173,7 +174,18 @@
|
||||||
form.find(".response-raw-response").text(panelText)
|
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) {
|
client.action(doc, key, params).then(function (data) {
|
||||||
var response = JSON.stringify(data, null, 2);
|
var response = JSON.stringify(data, null, 2);
|
||||||
|
@ -205,15 +217,20 @@
|
||||||
$('form.authentication-form').submit(function(event) {
|
$('form.authentication-form').submit(function(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const form = $(this).closest("form");
|
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_token_modal').modal('hide');
|
||||||
|
|
||||||
$('#auth-control').children().removeClass('active');
|
$('#auth-control').children().removeClass('active');
|
||||||
|
|
||||||
if (token) {
|
if (value) {
|
||||||
|
window.auth = {
|
||||||
|
'type': 'token',
|
||||||
|
'value': value,
|
||||||
|
};
|
||||||
$('#selected-authentication').text('token');
|
$('#selected-authentication').text('token');
|
||||||
$('#auth-control').find("[data-auth='token']").addClass('active');
|
$('#auth-control').find("[data-auth='token']").addClass('active');
|
||||||
} else {
|
} else {
|
||||||
|
window.auth = null;
|
||||||
$('#selected-authentication').text('none');
|
$('#selected-authentication').text('none');
|
||||||
$('#auth-control').find("[data-auth='none']").addClass('active');
|
$('#auth-control').find("[data-auth='none']").addClass('active');
|
||||||
}
|
}
|
||||||
|
@ -221,7 +238,7 @@
|
||||||
|
|
||||||
$('#auth-control').find("[data-auth='none']").click(function (event) {
|
$('#auth-control').find("[data-auth='none']").click(function (event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
window.token = null;
|
window.auth = null;
|
||||||
$('#selected-authentication').text('none');
|
$('#selected-authentication').text('none');
|
||||||
$('#auth-control').find("[data-auth='none']").addClass('active');
|
$('#auth-control').find("[data-auth='none']").addClass('active');
|
||||||
$('#auth-control').find("[data-auth='token']").removeClass('active');
|
$('#auth-control').find("[data-auth='token']").removeClass('active');
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
<li data-toggle="collapse" data-target="#auth-control" class="collapsed">
|
<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>
|
<a><i class="fa fa-user fa-lg"></i> Authentication</a> <span id="selected-authentication">none</span>
|
||||||
</li>
|
</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="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>
|
<li data-auth="token" data-toggle="modal" data-target="#auth_token_modal"><a href="#">token</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user