Change Elasticsearch auth Token


#1

So I’m using the Elasticsearch provider against a secured server that requires a token to be passed. The token can be set easily as the elastic provider doc explains when the provider is created. The problem is that we need to update the headers when the token is expired with a new token, but I haven’t found out how to update the headers of an existing provider.


#2

The fastest way is to access directly to the provider configuration:

const prov = cf.getProviderByConfig({ name: 'Provider Name' })
prov._providerCfg.headers = { Authorization: token }

#3

I see, after I asked I found that I also could unregister the provider, create a new one (same parameters with updated headers) and register it back. And it was working. But this way is more efficient.

Btw, If I need to integrate this with Studio (only working with custom apps now), do I have to do this or Studio takes care of it?


#4

Maybe you are looking for this https://chartfactor.com/doc/latest/studio_user_auth/#configredirecthtml?


#5

Oh I see, so this page is meant to be configured by us. I guess Studio is using whatever we use as header here to be passed to the provider:

        const providerAuth = {
          headers: {
            Authorization: `Bearer ${token}`,
          },
          expiration: Date.now() + Number(expiration_time) * 1000,
        };

I also guess headers and expiration are keys that should be explicitly set right?


#6

Exactly, it should be set because it is used by Studio to determine if it should ask for a re-login to update the token. Within the headers property you can specify the headers required by your provider (Authorization, Content-Type…etc.)