node-oauth icon indicating copy to clipboard operation
node-oauth copied to clipboard

do not assume utf-8 for GET requests

Open RokoTechnology opened this issue 3 years ago • 1 comments

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 avatar Jun 14 '22 21:06 RokoTechnology

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
} })

RokoTechnology avatar Jun 14 '22 21:06 RokoTechnology