# How to intercept all http request from kibana frontend going to backend through plugin?

**URL:** <https://discuss.elastic.co/t/how-to-intercept-all-http-request-from-kibana-frontend-going-to-backend-through-plugin/147397>\
**Category:** Kibana\
**Created:** [September 5, 2018, 11:50am UTC](https://discuss.elastic.co/t/how-to-intercept-all-http-request-from-kibana-frontend-going-to-backend-through-plugin/147397 "2018-09-05T11:50:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Parth\_Kalaria](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/parth_kalaria/32/61450_2.png) [@Parth\_Kalaria](https://discuss.elastic.co/u/Parth_Kalaria)\
**Post date:** [September 5, 2018, 11:50am UTC](https://discuss.elastic.co/t/how-to-intercept-all-http-request-from-kibana-frontend-going-to-backend-through-plugin/147397/1 "2018-09-05T11:50:51Z")

</div>

I want to intercept all http request from kibana and add jwtHeader in each of them. I tried writing a plugin in which I'm using $httpProvider.interceptors to intercept and add headers.

```
uiModules
.get('kibana', ['angular-jwt'])
.config(['$httpProvider', 'jwtOptionsProvider', function Authenticate($httpProvider, jwtOptionsProvider) {
  var refreshPromise;

  jwtOptionsProvider.config({
    tokenGetter: ['$q', '$timeout', 'jwtHelper', function ($q, $timeout, jwtHelper) {
      // setting authentication header
  });

  $httpProvider.defaults.withCredentials = true;
  $httpProvider.interceptors.push('jwtInterceptor');
}]);

```

But this seems to be called only when I go to this plugin page and also this interception only works on this plugin page only. If I go back to suppose Discover page then interceptor doesn't add any headers.

So how can I intercept all request going from kibana so I can add authentication headers? I've seen [#19060](https://github.com/elastic/kibana/issues/19060) but is it possible to do in kibana v6.3.2?

---

<div class="post-metadata">

**Author:** ![Nathan\_Reese](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nathan_reese/32/84829_2.png) [@Nathan\_Reese](https://discuss.elastic.co/u/Nathan_Reese)\
**Post date:** [September 5, 2018, 12:33pm UTC](https://discuss.elastic.co/t/how-to-intercept-all-http-request-from-kibana-frontend-going-to-backend-through-plugin/147397/2 "2018-09-05T12:33:31Z")

</div>

Kibana is moving away from angular and `$http`. In the future, all http requests will be made with [kfetch](https://github.com/elastic/kibana/blob/6.4/src/ui/public/kfetch/kfetch.ts), Kibana's wrapper around `fetch` (added in 6.4). Interceptor support has just been added to kfetch and will appear in 6.5 - [https://github.com/elastic/kibana/commit/1daa265ff82b58e54e658b8f5834aa5fe1701a9e](https://github.com/elastic/kibana/commit/1daa265ff82b58e54e658b8f5834aa5fe1701a9e)

Here is an example of how to add intercepters to the existing `$http`. [https://github.com/elastic/kibana/blob/master/x-pack/plugins/xpack\_main/public/hacks/check\_xpack\_info\_change.js#L90](https://github.com/elastic/kibana/blob/master/x-pack/plugins/xpack_main/public/hacks/check_xpack_info_change.js#L90).

If you are looking to add authentication to Kibana, Elastic's commercial features offer authentication. Starting in 6.3, the commercial features are even included in the default distribution so trying them out is just a one button process - under Management -\> License Management, click start trial.

---

<div class="post-metadata">

**Author:** ![Parth\_Kalaria](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/parth_kalaria/32/61450_2.png) [@Parth\_Kalaria](https://discuss.elastic.co/u/Parth_Kalaria)\
**Post date:** [September 10, 2018, 9:10am UTC](https://discuss.elastic.co/t/how-to-intercept-all-http-request-from-kibana-frontend-going-to-backend-through-plugin/147397/3 "2018-09-10T09:10:32Z")

</div>

Thanks, that resolved the issue

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 8, 2018, 9:10am UTC](https://discuss.elastic.co/t/how-to-intercept-all-http-request-from-kibana-frontend-going-to-backend-through-plugin/147397/4 "2018-10-08T09:10:39Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
