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

code.getToken() failing #173

Open
oliviazz opened this issue Apr 17, 2021 · 1 comment
Open

code.getToken() failing #173

oliviazz opened this issue Apr 17, 2021 · 1 comment

Comments

@oliviazz
Copy link

oliviazz commented Apr 17, 2021

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!

@shauryadhadwal
Copy link

shauryadhadwal commented Apr 28, 2021

"version": "4.3.3"
I was getting this error and fixed it by updating client config in OAuth2.0 Provider
Might be remotely related to yours.

{ error: 'invalid_client', error_description: 'Client authentication failed (e.g., unknown client, no client authentication included, or unsupported authentication method). The OAuth 2.0 Client supports client authentication method \'client_secret_post\', but method \'client_secret_basic\' was requested. You must configure the OAuth 2.0 client\'s \'token_endpoint_auth_method\' value to accept \'client_secret_basic\'.' }, code: 'EAUTH' }

Update this field:
token_endpoint_auth_method": "client_secret_basic"

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants