I was implementing this for use in a Cloudflare Worker. For local dev, I was using wrangler. For some reason, I was getting a w.getHeaders is undefined. I traced it down to this block of code:
|
const form = new FormData(); |
|
form.append('client_id', clientId); |
|
form.append('client_secret', clientSecret); |
|
form.append('jwt_token', token); |
|
|
|
const postOptions = { |
|
method: 'POST', |
|
body: form, |
|
headers: form.getHeaders() |
|
}; |
I'm wondering if it's because of const FormData = require('form-data'); where FormData is being the JavaScript FormData and not the form-data version as the JavaScript class doesn't have a getHeaders function.
Some debugging I did was added a console.log(form.getHeaders); and that logged out undefined as expected so it's certainly not the form-data one.