2

I'm trying to use the built in tool to get an OAuth 2.0 token for my requests. This seems pretty straightforward when reading the documentation and I set it up like this: screenshot from postman request

The issue is that the request for the token is sent with a content type of application/x-www-form-urlencoded. So the response I'm getting from the server is a 415 Unsupported Media Type I do not see a way to change the request content-type to application/json.

screenshot of postman console log

Am I missing something or is the only way to create a custom pre-request script?

Neil
  • 111
  • 2
  • 11

1 Answers1

3

https://github.com/oauthjs/node-oauth2-server/issues/92

application/x-www-form-urlencoded , is the supported content-type for Oauth

https://www.rfc-editor.org/rfc/rfc6749#section-4.1.3

If you want to create , you can use pre-requisite script something like:

https://gist.github.com/madebysid/b57985b0649d3407a7aa9de1bd327990

// Refresh the access token and set it into environment variable
pm.sendRequest({
    url:  pm.collectionVariables.get("zoho_accounts_endpoint") + "/oauth/v2/token", 
    method: 'POST',
    header: {
        'Accept': 'application/json',
        'Content-Type': 'application/x-www-form-urlencoded',
    },
    body: {
        mode: 'urlencoded',
        urlencoded: [
            {key: "client_id", value: pm.collectionVariables.get("zoho_client_id"), disabled: false},
            {key: "client_secret", value: pm.collectionVariables.get("zoho_client_secret"), disabled: false},
            {key: "refresh_token", value: pm.collectionVariables.get("zoho_refresh_token"), disabled: false},
            {key: "grant_type", value: 'refresh_token', disabled: false}
        ]
    }
}, function (err, res) {
    pm.collectionVariables.set("zoho_access_token", 'Zoho-oauthtoken ' + res.json().access_token);
});

Change it to JSON or what ever you want and store the value to a variable and use that as bearer {{token}}

Community
  • 1
  • 1
PDHide
  • 18,113
  • 2
  • 31
  • 46
  • 1
    I guess the answer is actually:`No, you can't because that would be against the understood spec.` EDIT: Thanks, BTW. I didn't know this. – Neil Feb 17 '21 at 16:52
  • In real world there exists number of "REST API is based on Oauth 2.0 Authorization framework as described in RFC 6749". Note: "based", not "is". We still need to authenticate against those APIs with Postman. – Jari Turkia May 07 '23 at 14:13