<p>I am following this link:
<a href="https://github.com/kubernetes-client/javascript" rel="nofollow noreferrer">https://github.com/kubernetes-client/javascript</a></p>

<p>and trying to list pods in the given namespace, here the code that I am referring:</p>

<pre><code>const k8s = require('@kubernetes/client-node');

const kc = new k8s.KubeConfig();
kc.loadFromDefault();

const k8sApi = kc.makeApiClient(k8s.CoreV1Api);

k8sApi.listNamespacedPod('abc').then((res) =&gt; {
    console.log(res.body);
});
</code></pre>

<p>I have successfully logged in to Kubernetes console, In the console, I am able to do the normal operation, but when I am running this code I am getting below error:</p>

<pre><code>(node:30816) UnhandledPromiseRejectionWarning: Error: Token is expired!
    at CloudAuth.updateAccessToken (D:\project\IOT-KT\dl\node_modules\@kubernetes\client-node\dist\cloud_auth.js:46:19)
    at CloudAuth.getToken (D:\project\IOT-KT\dl\node_modules\@kubernetes\client-node\dist\cloud_auth.js:24:18)
    at CloudAuth.&lt;anonymous&gt; (D:\project\IOT-KT\dl\node_modules\@kubernetes\client-node\dist\cloud_auth.js:15:32)
    at Generator.next (&lt;anonymous&gt;)
    at D:\project\IOT-KT\dl\node_modules\tslib\tslib.js:110:75
    at new Promise (&lt;anonymous&gt;)
    at Object.__awaiter (D:\project\IOT-KT\dl\node_modules\tslib\tslib.js:106:16)
    at CloudAuth.applyAuthentication (D:\project\IOT-KT\dl\node_modules\@kubernetes\client-node\dist\cloud_auth.js:14:24)
    at KubeConfig.&lt;anonymous&gt; (D:\project\IOT-KT\dl\node_modules\@kubernetes\client-node\dist\config.js:299:37)
    at Generator.next (&lt;anonymous&gt;)
(node:30816) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:30816) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
</code></pre>

<p>Just wanted to mention that RBAC is enabled on k8s cluster</p>

<p>My Config file looks like this:</p>

<pre><code>apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: LS0tLS1C..................Cg==
    server: https://&lt;removed&gt;.azmk8s.io:443
  name: removed&gt;
contexts:
- context:
    cluster: removed&gt;
    user: removed&gt;
  name: removed&gt;
current-context: removed&gt;
kind: Config
preferences: {}
users:
- name: removed&gt;
  user:
    auth-provider:
      config:
        apiserver-id: removed&gt;
        client-id: removed&gt;
        environment: removed&gt;
        tenant-id: removed&gt;
      name: azure
</code></pre>

<p>Please let me know what I am missing</p>

focode
<p>So, it appeared that as of now (Jan-2020) Javascript client library <a href="https://github.com/kubernetes-client/javascript/blob/master/src/cloud_auth.ts#L62" rel="nofollow noreferrer">doesn't  support</a> automatic rewriting of the config when it refreshes a token. </p>

<pre class="lang-js prettyprint-override"><code>private updateAccessToken(config: Config) {
    let cmd = config['cmd-path'];
    if (!cmd) {
        throw new Error('Token is expired!');
</code></pre>

<p>The workaround is to validate it manually by runing <code>kubectl version</code> which will refresh the token in your <code>kubeconfig</code> file.</p>

<p>If that works, the option is to add the following to the <code>kubeconfig</code>:</p>

<pre><code>user:
   ...
   cmd-path: kubectl
   cmd-args: version
</code></pre>

<p>Developers will definitely be ading better support for refreshing tokens to the client SDK.</p>

<p>Because there is already an <a href="https://github.com/kubernetes-client/javascript/blob/master/src/config.ts#L352" rel="nofollow noreferrer">utility</a>
that calls <code>exportConfig()</code> to write the config into a string (which could then be written into a file), so it's possible to fix the behavior.</p>

<p>To do it right a large-ish refactor of the authenticator interface is required. That will be done under this <a href="https://github.com/kubernetes-client/javascript/issues/399" rel="nofollow noreferrer">github issue track</a>.</p>
