OAuth token secret can't pass from redirect to callback


#1

I work on AdonisJS. I won’t use Adonis Ally because it’s not enough developed according to my needs.

My problem is : I can’t execute callback without OAuth token secret because I can’t pass this variable from redirect to callback. It’s a VueJS authenticator.

This authentication is for Tumblr login.

Constructor method (it works)

New instance of OAuth package (https://www.npmjs.com/package/oauth)

this.oa = new OAuth(
  'https://www.tumblr.com/oauth/request_token',
  'https://www.tumblr.com/oauth/access_token',
  Env.get('TUMBLR_ID'),
  Env.get('TUMBLR_SECRET'),
  '1.0',
  `${Env.get('APP_URL')}/networks/tumblr/callback`,
  'HMAC-SHA1'
)

Redirect method (it works)

Redirect method who generate new URL to redirect user on authorization Tumblr page.

async redirect ({response}) {
  try {
    const url = await new Promise((resolve, reject) => {
      this.oa.getOAuthRequestToken((error, oAuthToken, oAuthTokenSecret, results) => {
        resolve('https://www.tumblr.com/oauth/authorize?oauth_token=' + oAuthToken)
      })
    })

    return response.status(200).send({ url })
  } catch (error) {
    console.error(error)
  }
}

Callback method (doesn’t works)

The problem is I can’t get oAuthTokenSecret variable from session/cookie/Redis, etc…

I don’t know how I can get this and it’s mandatory to use OAuth callback.

async callback ({auth, response, request}) {
  try {
    // const user = await auth.getUser()

    const oAuthTokenSecret = 'I want get oAuthTokenSecret here'

    this.oa.getOAuthAccessToken(
      request.input('oauth_token'),
      oAuthTokenSecret,
      request.input('oauth_verifier'),
      (error, oAuthAccessToken, oAuthAccessTokenSecret, results) => {
        if (error) {
          console.error(error)
          throw new ErrorManager(404, 'Error', 'Error occured while getting access token')
        }

        this.oa.get('https://api.tumblr.com/v2/user/info',
          oAuthAccessToken,
          oAuthAccessTokenSecret,
          (error, data, result) => {
            if (error) {
              throw new ErrorManager(404, 'Error', 'Error occured...')
            }

            data = JSON.parse(data)

            console.log(data) // no data
          })
      })

    return response.status(200).send(true)
  } catch (error) {
    console.error(error)
  }
}

I get back this error on callback:

oauth_signature does not match expected value