Fixed #52 - Added Basic Auth support.

This commit is contained in:
Alexander Zobnin
2015-07-12 11:32:51 +03:00
parent d716c266ba
commit d20bd8e821
2 changed files with 24 additions and 5 deletions

View File

@@ -9,11 +9,13 @@ function (angular, _) {
module.factory('ZabbixAPI', function($q, backendSrv) {
function ZabbixAPI(api_url, username, password) {
function ZabbixAPI(api_url, username, password, basicAuth, withCredentials) {
// Initialize API parameters.
this.url = api_url;
this.username = username;
this.password = password;
this.url = api_url;
this.username = username;
this.password = password;
this.basicAuth = basicAuth;
this.withCredentials = withCredentials;
}
var p = ZabbixAPI.prototype;
@@ -45,6 +47,13 @@ function (angular, _) {
}
};
if (this.basicAuth || this.withCredentials) {
options.withCredentials = true;
}
if (this.basicAuth) {
options.headers.Authorization = this.basicAuth;
}
var self = this;
return backendSrv.datasourceRequest(options).then(function (response) {
if (!response.data) {
@@ -88,6 +97,14 @@ function (angular, _) {
},
};
if (this.basicAuth || this.withCredentials) {
options.withCredentials = true;
}
if (this.basicAuth) {
options.headers = options.headers || {};
options.headers.Authorization = this.basicAuth;
}
return backendSrv.datasourceRequest(options).then(function (result) {
if (!result.data) {
return null;