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

Get access token before importing users #267

Merged
merged 9 commits into from
May 31, 2018
Merged

Get access token before importing users #267

merged 9 commits into from
May 31, 2018

Conversation

Floppy
Copy link
Contributor

@Floppy Floppy commented May 28, 2018

Get an access token before running importUsers. Resolves #266.

The changes are more minimal than they look, because of the pre-commit formatter. Description of change added in comments on the relevant lines.

}
},
connection_id: data.connection_id
var promise = options.tokenProvider.getAccessToken().then(function(access_token) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before the existing request promise, we call getAccessToken from the provider we were passed on creation. This is then passed a function that wraps the existing code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the right way to do it, but I'm not an expert with the various ways this codebase handles authentication, so if it should do something different as well / instead, please let me know.

{
url: url,
method: method,
headers: extend({ Authorization: `Bearer ${access_token}` }, headers),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The token is then added to the headers.

@Floppy Floppy changed the title WIP: Get access token before importing users Get access token before importing users May 28, 2018
@luisrudge
Copy link
Contributor

Why can't you just use the RestClient that is created in the constructor?

@Floppy
Copy link
Contributor Author

Floppy commented May 29, 2018

I did wonder that, but was working on the assumption (before checking here) that this one rolls its own for some specific reason. Obviously that would be ideal, to use create. No blockers that you know of?

@Floppy
Copy link
Contributor Author

Floppy commented May 29, 2018

I suspect (though I've not tried it to check yet) that it's because this method submits a multipart form, which the base rest client doesn't support. But as I say I've not tried, was starting with a minimal change 😄

@luisrudge
Copy link
Contributor

oh yeah, you're probably right. multipart/form-data is probably the reason. I like your solution. Any ideas on why codecov is complaining?

@Floppy
Copy link
Contributor Author

Floppy commented May 30, 2018

I think because it's quite a short diff, and one of the lines isn't covered (and wasn't before), so it fails the 95% diff coverage test. The coverage value overall has gone up though :)

@luisrudge
Copy link
Contributor

Found it. Can you write a test for when the request fails?
image

@Floppy
Copy link
Contributor Author

Floppy commented May 31, 2018

Just realised that those last changes replicate some of what @mikemeerschaert did in #243. But now it has tests :)

@luisrudge luisrudge merged commit 7a2856d into auth0:master May 31, 2018
@luisrudge
Copy link
Contributor

Thanks for the PR 🎉

@luisrudge luisrudge added this to the v2.11.0 milestone Jul 25, 2018
@Floppy Floppy deleted the auth-before-import branch October 30, 2018 11:57
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