Skip to content
This repository was archived by the owner on Jan 20, 2024. It is now read-only.
This repository was archived by the owner on Jan 20, 2024. It is now read-only.

code.getToken() failing  #173

Open
Open
@oliviazz

Description

@oliviazz

I'm getting the following error after trying to implement js-client-oauth2 in my express app. In my callback function, I'm copying the authorization code grant flow , calling:

ouraAuth.code.getToken(req.originalUrl)
    .then(function (user) {
      console.log(user) //=> { accessToken: '...', tokenType: 'bearer', ... }
 
      // Refresh the current users access token.
      user.refresh().then(function (updatedUser) {
        console.log(updatedUser !== user) //=> true
        console.log(updatedUser.accessToken)
      }).catch((error) => {
        console.log(error,'Promise error on user refresh');
      });
 
      // Sign API requests on behalf of the current user.
      user.sign({
        method: 'get',
        url: 'http://example.com'
      })
 
      // We should store the token into a database.
      return res.send(user.accessToken)
    }).catch((error) => {
        console.log(error,'Promise error on code.getToken');
      });
 

Although req.OriginalUrl is valid, and I set up my ouraAuth according to the protocol, I am catching the following error on my outer code.getToken request:

"TypeError: Body is destroyed
    at getRawBody (/Users/oliviazhang/iw-app/my_app/node_modules/servie/dist/common.js:30:15)
    at Object.useRawBody (/Users/oliviazhang/iw-app/my_app/node_modules/servie/dist/common.js:15:21)
    at HttpResponse.text (/Users/oliviazhang/iw-app/my_app/node_modules/servie/dist/node.js:79:34)
    at /Users/oliviazhang/iw-app/my_app/node_modules/client-oauth2/src/request/index.js:18:16
    at process._tickCallback (internal/process/next_tick.js:68:7) 'Promise error'

Any help or insight is appreciated - thank you so much!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions