Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSD plugin: get user information from request on server side #864

Open
eloyobara-atos opened this issue Oct 11, 2021 · 1 comment
Open
Labels
enhancement New feature or request

Comments

@eloyobara-atos
Copy link

Is your feature request related to a problem? Please describe.

Hi, I'm trying to write an OpenSearch Dashboards plugin and, on the server side, I don't know how to get the user's information (e.g.: username, roles) from the context or request objects. See sample code below:

...
public setup(core: CoreSetup) {
  const router = core.http.createRouter();
  router.post(
    {
      path: '/api/test',
      options: { authRequired: true },
      validate: {
        body: schema.any()
      }
    },
    async (context, request, response) => {

      // **** Get user information here! ****
  
      return response.ok({
        body: 'some data',
        headers: {
          'content-type': 'text/html'
        }
      } as any);
    }
  );
}

Describe the solution you'd like

I have found this in Elastic forums: https://discuss.elastic.co/t/unable-to-get-the-username-and-roles-in-kibana-7-9-through-the-legacy-and-new-platforms/249296
In x-pack there's a getCurrentUser() API in the Security Plugin. It would be nice we could have something similar in OpenSearch Dashboards.

Describe alternatives you've considered

I couldn't find any alternatives...

Thanks!

@eloyobara-atos eloyobara-atos added the enhancement New feature or request label Oct 11, 2021
@ananzh
Copy link
Member

ananzh commented Oct 18, 2021

Hello @eloyobara-atos, opensearch dashboards is forked from 7.10.2. So we could do the same. Here is an example:

var { Client } = require('@opensearch-project/opensearch');
var fs = require('fs');
var client = new Client({
    node: protocol + '://' + auth + '@' + host + ':' + port,
    ssl: {
        ca: fs.readFileSync(ca_certs_path),
        // You can turn off certificate verification (rejectUnauthorized: false) if you're using self-signed certificates with a hostname mismatch.
        // cert: fs.readFileSync(client_cert_path),
        // key: fs.readFileSync(client_key_path)
    }
})

Here is the reference to the complete example. We are forking the nodejs package but due to this issue, opensearch nodejs client can not be used directly in dashboards. But it could be used for simple plugins.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants