From c9d6321f382cd7a30f0faa927b43cd5b97d03b06 Mon Sep 17 00:00:00 2001 From: Jared Wiltshire Date: Thu, 26 May 2016 15:13:29 +1000 Subject: [PATCH] Allow for proxying Authorization header and automatically convert (#4832) Authorization header to X-DS-Authorization in backend_srv.js --- pkg/api/dataproxy.go | 7 +++++++ public/app/core/services/backend_srv.js | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/pkg/api/dataproxy.go b/pkg/api/dataproxy.go index b00ef595161..9a062ddfd2d 100644 --- a/pkg/api/dataproxy.go +++ b/pkg/api/dataproxy.go @@ -55,6 +55,13 @@ func NewReverseProxy(ds *m.DataSource, proxyPath string, targetUrl *url.URL) *ht req.Header.Add("Authorization", util.GetBasicAuthHeader(ds.BasicAuthUser, ds.BasicAuthPassword)) } + dsAuth := req.Header.Get("X-DS-Authorization") + if len(dsAuth) > 0 { + req.Header.Del("X-DS-Authorization") + req.Header.Del("Authorization") + req.Header.Add("Authorization", dsAuth) + } + // clear cookie headers req.Header.Del("Cookie") req.Header.Del("Set-Cookie") diff --git a/public/app/core/services/backend_srv.js b/public/app/core/services/backend_srv.js index ff3784ab45e..f27e427c70b 100644 --- a/public/app/core/services/backend_srv.js +++ b/public/app/core/services/backend_srv.js @@ -96,6 +96,11 @@ function (angular, _, coreModule, config) { var requestIsLocal = options.url.indexOf('/') === 0; var firstAttempt = options.retry === 0; + if (requestIsLocal && options.headers && options.headers.Authorization) { + options.headers['X-DS-Authorization'] = options.headers.Authorization; + delete options.headers.Authorization; + } + return $http(options).then(null, function(err) { // handle unauthorized for backend requests if (requestIsLocal && firstAttempt && err.status === 401) {