Reputation: 333
I was looking through other posts for replacements for Curl in nodejs, especially with complex behaviors as such:
-H 'Authorization: Basic MjJCTUpROjczNzY0YzkwOWQ2MDczZDRjYzA0YWZhZDBlMDVhMThm' \
--data "clientId=22BMJQ" \
--data "grant_type=authorization_code" \
--data "redirect_uri=https%3A%2F%2Fexample.com%2Fcallback" \
--data "code=5f10eff73e8daf2049be22bb079beee57036c7a5" \
-H 'Content-Type: application/x-www-form-urlencoded' \
https://api.fitbit.com/oauth2/token
Are there any packages you would recommend or have ideas on how the above request could be replicated in nodejs?
Upvotes: 1
Views: 266
Reputation: 29243
Have a look at OpenId Client, which is a certified library. It will make life easier once you're familiar with it.
Here are a couple of links that you might find useful, to understand the basics of the coding model:
Upvotes: 1
Reputation: 510
In case you don't only want to call OAuth 2.0 endpoints but also other endpoints with the curl alternative, I made good experiences with node-fetch. The code with node-fetch is more readable and you can work with response very easily in JavaScript.
Upvotes: 2