Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
320 views
in Technique[技术] by (71.8m points)

Is there a way to change the Content Type for a Postman OAuth 2 Client Credentials request?

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?

question from:https://stackoverflow.com/questions/65599951/is-there-a-way-to-change-the-content-type-for-a-postman-oauth-2-client-credentia

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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

https://tools.ietf.org/html/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}}


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...