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

Fix undefined tokenProvider when access token is provided. #642

Merged
merged 2 commits into from
Sep 20, 2021

Conversation

Gilighost
Copy link
Contributor

Changes

When using the ManagementClient, tokenProvider is expected to be a member of the options object which is passed to various Managers such as the JobsManager. However, when the ManagementClient is configured with only a domain and a token, tokenProvider is not assigned to the options object which results in an error when a Manager attempts to access options.tokenProvider.getAccessToken because tokenProvider is undefined.

e.g. https://github.com/auth0/node-auth0/blob/master/src/management/JobsManager.js#L142

This PR moves the line which assigns the tokenProvider to the options object out of an if statement so that the assignment is performed on all code paths.

Testing

Test this by using the ManagementClient with an access token as specified in the docs.
https://auth0.github.io/node-auth0/module-management.ManagementClient.html

var ManagementClient = require('auth0').ManagementClient;
var auth0 = new ManagementClient({
  domain: '{YOUR_ACCOUNT}.auth0.com',
  token: '{YOUR_API_V2_TOKEN}'
});

Then attempt to use a method provided by the JobsManager. e.g. import users job

Previously, this would throw an error:

TypeError: Cannot read property 'getAccessToken' of undefined

But with this change, it should start the job as expected.

  • This change adds unit test coverage
  • This change adds integration test coverage

Checklist

@Gilighost Gilighost requested a review from a team as a code owner July 29, 2021 20:23
@davidpatrick davidpatrick modified the milestones: v2.36.0, vNext Sep 20, 2021
@davidpatrick
Copy link
Contributor

Thanks @Gilighost

@davidpatrick davidpatrick merged commit bcc1c0d into auth0:master Sep 20, 2021
@adamjmcgrath adamjmcgrath mentioned this pull request Oct 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants