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

Allow to decentralise Management API token cache #792

Closed
KillianHmyd opened this issue Mar 14, 2023 · 2 comments
Closed

Allow to decentralise Management API token cache #792

KillianHmyd opened this issue Mar 14, 2023 · 2 comments
Labels
enhancement An enhancement or improvement to the SDK that could not be otherwise categorized as a new feature

Comments

@KillianHmyd
Copy link
Contributor

Describe the problem you'd like to have solved

As the cache of the Management API's token is local to the execution process we end-up generating a lot of Machine-to-Machine tokens when scaling our application horizontally. Having a way to decentralised the cache would help us to reduce the number of generated tokens.

Describe the ideal solution

Ideally we could pass a method to the token properties to handle ourselves the caching mechanism:

const auth0ManagementClient = new ManagementClient({
  token: () => Promise.resolve('my-token')
  clientId,
  domain,
  audience,
  scope,
});

We can also imagine leveraging on the existing Automatic Management API Token Retrieval features:

const auth0ManagementClient = new ManagementClient({
  tokenProvider: {
     enableCache: true,
     setCache: (token) => saveCachedToken(token),
     getCache: () => getCachedToken()
  }
});

Alternatives and current work-arounds

Currently the only solution I see is to create multiple instance of the ManagementClient to control which token is passed to it.

Additional information, if any

@adamjmcgrath
Copy link
Contributor

Hi @KillianHmyd - thanks for raising this

Happy to proceed with your PR, although you can also just do

const auth0ManagementClient = new ManagementClient({ ... });
auth0ManagementClient.tokenProvider = {
  getAccessToken() {
    return Promise.resolve('my-token');
  }
}

@adamjmcgrath adamjmcgrath added the enhancement An enhancement or improvement to the SDK that could not be otherwise categorized as a new feature label Mar 14, 2023
@adamjmcgrath
Copy link
Contributor

Fixed by #793

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement or improvement to the SDK that could not be otherwise categorized as a new feature
Projects
None yet
Development

No branches or pull requests

2 participants