ciaranj / node-oauth

OAuth wrapper for node.js
MIT License
2.44k stars 660 forks source link

do not assume utf-8 for GET requests #370

Open RokoTechnology opened 2 years ago

RokoTechnology commented 2 years ago

GET body is always returned in utf-8 as per

https://github.com/ciaranj/node-oauth/blob/master/lib/oauth.js#L404

this is causing issue while retrieving OAuth secured images, for example

https://developer.twitter.com/en/docs/twitter-api/v1/direct-messages/message-attachments/guides/retrieving-media

RokoTechnology commented 2 years ago

workaround would be to call _prepareParameters and then feed that as authorization header to your http client of choice

const headers = ctx.oa._prepareParameters(config.oauth.oauth_token, config.oauth.oauth_token_secret, 'GET', params.uri)

const strHeaders = 'OAuth ' + headers.map(h => h.map(hh => encodeURIComponent(hh)).join('="')).join('", ')

const result = await ctx.got(params.uri, { headers: {
  'Authorization': strHeaders
} })