# Access XPack user's username from a plugin

**URL:** https://discuss.elastic.co/t/access-xpack-users-username-from-a-plugin/114969
**Category:** Elasticsearch
**Created:** [January 10, 2018, 10:08pm UTC](https://discuss.elastic.co/t/access-xpack-users-username-from-a-plugin/114969 "2018-01-10T22:08:46Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![mostdispleased](https://avatars.discourse-cdn.com/v4/letter/m/e47774/32.png) [@mostdispleased](https://discuss.elastic.co/u/mostdispleased)
#### Post date: [January 10, 2018, 10:08pm UTC](https://discuss.elastic.co/t/access-xpack-users-username-from-a-plugin/114969/1 "2018-01-10T22:08:46Z")

</div>

We have XPack installed on ES / Kibana 5.5.1. Is it possible from within a plugin to access the current Kibana user's username, and optionally if the user is viewing a dashboard to retrieve the dashboard name (not the hash)?

I have tried various service / uiExport combinations to no avail.

```
// Main plugin registration.
exports.default = function (kibana) {
  return new kibana.Plugin({
                id: 'bit_test_plugin',
                require: ['kibana', 'elasticsearch'],

                // There are a couple of ways to inject content into Kibana,
                // all of them are defined here. "hacks" is special in that it 
                // loads on every pages, whereas app may only load when the user
                // visits your plugin directly.
                uiExports: {
                        chromeNavControls: [
                                'plugins/bit_test_plugin/branding'
                        ],
                        hacks: [
                                'plugins/bit_test_plugin/hack.js'
                        ],
                        app: {
                                title: 'BIT Test Plugin',
                                description: 'Performs logging and adds custom navigation',
                                main: 'plugins/bit_test_plugin/app',
                                hidden: false // In production we will hide this
                        }
                },
                init(server, options){
                        console.warn('Init BIT Test Plugin from index.js');

                        // This defines an API request when you access 
                        // http://<kibana_url>/api/bit_test_plugin/ping
                        // We will use this to send the module 1000 ping since 
                        // we can access user IP address and hopefully one day get
                        // the dashboard name.
                        server.route({
                                path: '/api/bit_test_plugin/ping',
                                method: 'GET',
                                handler(req, reply) {
                                        // more to come here in the next step
                                        reply("Hello World");

                                        // We have the IP Address!
                                        var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;

                                        // TODO: Find dashbaord name! Note: This should only be available when 
                                        // Viewing a dashboard. We only want to log when users are viewing dashboards.
                                        var dashboard = "";

                                        if(dashboard != "")
                                                console.warn("User's IP Address: " + ip + " User is viewing dashboard: " + dashboard);
                                        else
                                                console.log("User is not viewing a dashboard");
                                }
                        });
                }
  });
};

module.exports = exports['default'];
```

---

<div class="post-metadata">

### Author: ![cjcenizal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cjcenizal/32/11216_2.png) [@cjcenizal](https://discuss.elastic.co/u/cjcenizal)
#### Post date: [January 11, 2018, 5:22pm UTC](https://discuss.elastic.co/t/access-xpack-users-username-from-a-plugin/114969/2 "2018-01-11T17:22:00Z")

</div>

Hi there, we don't yet officially support plugin development, so I won't be able to fully answer your question. However, there's some info available at [How to get currently logged in USERID in plugin?](https://discuss.elastic.co/t/how-to-get-currently-logged-in-userid-in-plugin/58627/8) which looks relevant and might be able to help you.

Thanks,  
CJ

---

<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: [February 8, 2018, 5:22pm UTC](https://discuss.elastic.co/t/access-xpack-users-username-from-a-plugin/114969/3 "2018-02-08T17:22:02Z")

</div>

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