usebruno / bruno

Opensource IDE For Exploring and Testing Api's (lightweight alternative to postman/insomnia)
https://www.usebruno.com/
MIT License
21.54k stars 1.01k forks source link

OAuth 2.0 - Client credentials always returning "'undefined' is not valid JSON" #2452

Open eduardoscamargo opened 2 weeks ago

eduardoscamargo commented 2 weeks ago

I have checked the following:

Describe the bug

I am trying to send a request using OAuth2 - Client Credentials. No matter the content of the credentials parameters I get a message Error invoking remote method 'send-http-request': SyntaxError: "undefined" is not valid JSON.

(Screenshot has mocked values, I tested with the real/correct values and got the same error message)

Version: v1.19.0

.bru file to reproduce the bug

No response

Screenshots/Live demo link

image
gemiusz commented 1 week ago

@eduardoscamargo I can't reproduce this: image

Please provide bru file with this issue.

I'm not sure how this functionality should work so need explanation from any DEV :) As I see when I set URL as 'test' then is going POST to 127.0.0.1:80 :

2024-06-14 18:50:19.391 Request received:
127.0.0.1 - POST /test

Accept: [application/json, text/plain, */*]
Content-Type: [application/x-www-form-urlencoded]
request-start-time: [1718383819286]
User-Agent: [axios/1.7.2]
Content-Length: [74]
Accept-Encoding: [gzip, compress, deflate, br]
Host: [localhost]
Connection: [close]
grant_type=client_credentials&client_id=test&client_secret=test&scope=test

So I think that in your case something send response that cannot be parsed correctly. Can you provide this response ?

sylvainlegault commented 1 week ago

Not sure if that can help but I have the same issue, this seems to happen when using GraphQL as a simple post works for the same oauth2 settings. There is nothing logged in the console nor in Timeline just showing < Error Looks like the request are never sent. Might be because Graphql is not JSON

sylvainlegault commented 6 days ago

Did some troubleshooting, but I don't know the code base enough :(

But the problem seems to be related to this part from ipc/network/index.js


    // if this is a graphql request, parse the variables, only after interpolation
    // https://github.com/usebruno/bruno/issues/884
    if (request.mode === 'graphql') {
      request.data.variables = JSON.parse(request.data.variables);
    }

I tried skipping this but doesn't solve the issue, I get further without exception but I get the auth response instead of the graphql response, so something else is not working. Looks like oauth2 doesn't play well with graphql and doesn't continue with the grapqh request itself.

I cannot share my environment since this is a private endpoint. But I can help with testing any fixes if needed.

Thanks