mrsarm / reqclient

Node.js module that uses `request` to make requests, but adds `Promise` supports, and many useful features
https://www.npmjs.com/package/reqclient
Apache License 2.0
8 stars 1 forks source link

invalid_request, can't post parameters #10

Closed enisgur closed 5 years ago

enisgur commented 6 years ago

I need help to get my access_token. it had been a week but still could't find out how, and decide to request help from here. I am trying to request post to oauth.opskins but it doesn't see my parametes. How can I send required parameters to server?

var client = new RequestClient({
            baseUrl:"https://oauth.opskins.com/v1/",
            debugRequest:true, debugResponse:true,
            auth:{
                user: '**my_client_id_here**',
                pass: '**my_secret_here**'
            }
        });

        var resp = client.post("access_token", {"grant_type": "authorization_code", "code":`${req.query.code}`},{headers: {"authorization":"Basic **my_key-here**"}});

I am getting this output

[Response access_token]<- Status 400 - {"error":"invalid_request","error_description":"The grant_type parameter is required"}

mrsarm commented 6 years ago

Hi @enisgur ,

If you are trying to access to a protected service with OAuth2, you shouldn't need to make the request manually, you only need to setup properly the Oauth2 settings, and before try to access to any endpoint in your secured service, reqclient will try to authenticate first. Take a look a the Twitter example here,where the intend is to try to access to the "trends/place.json" endpoint, but because RequestClient object was created with the oauth2 settings, the library try first to get the token using those settings against the OAuth2 endpoint.

But taking one more look to your example, you are trying to send also an "authorization" header, with a "Basic" token, so I not sure what is your intend.

But here are some observations:

mrsarm commented 5 years ago

Hey @enisgur ,

Did you solve the issue?

enisgur commented 5 years ago

thank you for your help. Yes I solve the issue. Thanks again