mirror of
https://github.com/overte-org/overte.git
synced 2025-04-08 19:14:59 +02:00
fix for OAuth OPTIONS firing on XHR 302
This commit is contained in:
parent
5617860fe4
commit
cf92144748
2 changed files with 47 additions and 24 deletions
|
@ -2,11 +2,11 @@ $(document).ready(function(){
|
|||
// setup the underscore templates
|
||||
var nodeTemplate = _.template($('#nodes-template').html());
|
||||
var queuedTemplate = _.template($('#queued-template').html());
|
||||
|
||||
|
||||
// setup a function to grab the assignments
|
||||
function getNodesAndAssignments() {
|
||||
$.getJSON("nodes.json", function(json){
|
||||
|
||||
|
||||
json.nodes.sort(function(a, b){
|
||||
if (a.type === b.type) {
|
||||
if (a.uptime < b.uptime) {
|
||||
|
@ -16,36 +16,50 @@ $(document).ready(function(){
|
|||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (a.type === "agent" && b.type !== "agent") {
|
||||
return 1;
|
||||
} else if (b.type === "agent" && a.type !== "agent") {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (a.type > b.type) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
if (a.type < b.type) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
$('#nodes-table tbody').html(nodeTemplate(json));
|
||||
}).fail(function(jqXHR, textStatus, errorThrown) {
|
||||
// we assume a 401 means the DS has restarted
|
||||
// and no longer has our OAuth produced uuid
|
||||
// so just reload and re-auth
|
||||
if (jqXHR.status == 401) {
|
||||
location.reload();
|
||||
}
|
||||
});
|
||||
|
||||
$.getJSON("assignments.json", function(json){
|
||||
|
||||
$.getJSON("assignments.json", function(json){
|
||||
$('#assignments-table tbody').html(queuedTemplate(json));
|
||||
}).fail(function(jqXHR, textStatus, errorThrown) {
|
||||
// we assume a 401 means the DS has restarted
|
||||
// and no longer has our OAuth produced uuid
|
||||
// so just reload and re-auth
|
||||
if (jqXHR.status == 401) {
|
||||
location.reload();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// do the first GET on page load
|
||||
getNodesAndAssignments();
|
||||
// grab the new assignments JSON every two seconds
|
||||
var getNodesAndAssignmentsInterval = setInterval(getNodesAndAssignments, 2000);
|
||||
|
||||
|
||||
// hook the node delete to the X button
|
||||
$(document.body).on('click', '.glyphicon-remove', function(){
|
||||
// fire off a delete for this node
|
||||
|
@ -57,10 +71,10 @@ $(document).ready(function(){
|
|||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
$(document.body).on('click', '#kill-all-btn', function() {
|
||||
var confirmed_kill = confirm("Are you sure?");
|
||||
|
||||
|
||||
if (confirmed_kill == true) {
|
||||
$.ajax({
|
||||
url: "/nodes/",
|
||||
|
|
|
@ -2091,22 +2091,31 @@ bool DomainServer::isAuthenticatedRequest(HTTPConnection* connection, const QUrl
|
|||
// the user does not have allowed username or role, return 401
|
||||
return false;
|
||||
} else {
|
||||
// re-direct this user to OAuth page
|
||||
static const QByteArray REQUESTED_WITH_HEADER = "X-Requested-With";
|
||||
static const QString XML_REQUESTED_WITH = "XMLHttpRequest";
|
||||
|
||||
// generate a random state UUID to use
|
||||
QUuid stateUUID = QUuid::createUuid();
|
||||
if (connection->requestHeaders().value(REQUESTED_WITH_HEADER) == XML_REQUESTED_WITH) {
|
||||
// unauthorized XHR requests get a 401 and not a 302, since there isn't an XHR
|
||||
// path to OAuth authorize
|
||||
connection->respond(HTTPConnection::StatusCode401, UNAUTHENTICATED_BODY);
|
||||
} else {
|
||||
// re-direct this user to OAuth page
|
||||
|
||||
// add it to the set so we can handle the callback from the OAuth provider
|
||||
_webAuthenticationStateSet.insert(stateUUID);
|
||||
// generate a random state UUID to use
|
||||
QUuid stateUUID = QUuid::createUuid();
|
||||
|
||||
QUrl authURL = oauthAuthorizationURL(stateUUID);
|
||||
// add it to the set so we can handle the callback from the OAuth provider
|
||||
_webAuthenticationStateSet.insert(stateUUID);
|
||||
|
||||
Headers redirectHeaders;
|
||||
QUrl authURL = oauthAuthorizationURL(stateUUID);
|
||||
|
||||
redirectHeaders.insert("Location", authURL.toEncoded());
|
||||
Headers redirectHeaders;
|
||||
|
||||
connection->respond(HTTPConnection::StatusCode302,
|
||||
QByteArray(), HTTPConnection::DefaultContentType, redirectHeaders);
|
||||
redirectHeaders.insert("Location", authURL.toEncoded());
|
||||
|
||||
connection->respond(HTTPConnection::StatusCode302,
|
||||
QByteArray(), HTTPConnection::DefaultContentType, redirectHeaders);
|
||||
}
|
||||
|
||||
// we don't know about this user yet, so they are not yet authenticated
|
||||
return false;
|
||||
|
|
Loading…
Reference in a new issue