Fixed #52 - Added Basic Auth support.
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user