auth0 / node-auth0

Node.js client library for the Auth0 platform.
MIT License
628 stars 307 forks source link

Missing property `tokenProvider` on management client #949

Closed danursin closed 11 months ago

danursin commented 11 months ago

Checklist

Description

The migration guide to v4 includes an entry that getAccessToken has been renamed to tokenProvider.getAccessToken but the client does not expose the tokenProvider as a property and the exports from the top-level of the package do not export the TokenProvider class, so instantiating it directly is not clear. The migration guide makes it seem like this should expose tokenProvider as a property of the client, like actions, emails, etc.

The use case for us is we use machine tokens in our backend tasks to authenticate across our microservices.

// v3
const mgmtClient = new ManagementClient({
    clientId,
    clientSecret,
    domain,
    audience,
    tokenProvider: {
        enableCache: true
    }
});

const token = await mgmtClient.getAccessToken();

const response = await fetch(url, { 
   headers: {
      Authorization: `Bearer ${token`}
   }
});

Reproduction

v4

import { ManagementClient } from "auth0";

const mgmtClient = new ManagementClient({
    domain,
    clientId,
    clientSecret,
    audience
});

const token = await mgmtClient.tokenProvider.getAccessToken(); // mgmtClient does not have property tokenProvider
import { TokenProvider } from "auth0"; // not exported

Additional context

No response

node-auth0 version

4.0.1

Node.js version

18

frederikprijck commented 11 months ago

That was a mistake in our migration guide and has been fixed, see https://github.com/auth0/node-auth0/commit/12d8b5a482d783239be6a2b62c049c83a4339c95

What you want to use is oauth.clientCredentialsGrant (on AuthenticationClient)`, our ManagementClient is not intended to be used to get tokens to be used outside of the ManagementClient. For that, we have the AuthenticationClient.