Commit 0be2065d authored by Alain Takoudjou's avatar Alain Takoudjou Committed by Rafael Monnerat

slapos_web: get json schema with basic authentication if credentials are set in URL

In Gitlab,  if URL is like https://USERNAME:PASSWORD@somedomain.com then gitlab will return 401 and ask for basic Authentication.

For this kind of URL, we simply extract username and password and send ajax request with Basic Auth.

/reviewed-on nexedi/slapos.core!163
parent b8c1ca76
/*jslint nomen: true, maxlen: 200, indent: 2*/
/*global window, rJS, console, RSVP, jQuery, jIO, tv4, URI, JSON, $ */
(function (window, rJS, $, RSVP) {
/*global window, rJS, console, RSVP, jQuery, jIO, tv4, URI, JSON, $, btoa */
(function (window, rJS, $, RSVP, btoa) {
"use strict";
var gk = rJS(window);
function getJSON(url) {
var protocol = URI(url).protocol();
var uri = URI(url),
headers = {},
protocol = uri.protocol();
if (protocol === "http" && URI(window.location).protocol() == "https") {
throw new Error("You cannot load http JSON in https page");
}
if (protocol === "http" || protocol === "https") {
if (uri.username() !== "" && uri.password() !== "") {
headers = {
Authorization: "Basic " + btoa(uri.username() + ":" + uri.password())
};
}
}
return RSVP.Queue()
.push(function () {
return jIO.util.ajax({
url: url
url: url,
headers: headers
})
.then(function (evt) {
return evt.target.responseText;
......@@ -239,4 +249,4 @@
});
});
});
}(window, rJS, $, RSVP));
\ No newline at end of file
}(window, rJS, $, RSVP, btoa));
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment