【问题标题】:Is there a way to change the Content Type for a Postman OAuth 2 Client Credentials request?有没有办法更改 Postman OAuth 2 客户端凭据请求的内容类型?
【发布时间】:2021-04-12 10:42:38
【问题描述】:

我正在尝试使用内置工具为我的请求获取 OAuth 2.0 令牌。在阅读文档时,这似乎很简单,我将其设置如下:

问题是令牌请求是使用application/x-www-form-urlencoded 的内容类型发送的。所以我从服务器得到的响应是 415 Unsupported Media Type 我看不到将请求内容类型更改为 application/json 的方法。

我是否遗漏了什么或者是创建自定义预请求脚本的唯一方法?

【问题讨论】:

    标签: oauth-2.0 postman content-type http-status-code-415 clientcredential


    【解决方案1】:

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

    application/x-www-form-urlencoded ,是 Oauth 支持的内容类型

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

    如果要创建,可以使用先决条件脚本,例如:

    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);
    });
    

    将其更改为 JSON 或您想要的任何内容,并将值存储到变量中并将其用作承载 {{token}}

    【讨论】:

    • 我猜答案实际上是:No, you can't because that would be against the understood spec. 编辑:谢谢,顺便说一句。我不知道这个。
    猜你喜欢
    • 1970-01-01
    • 2017-11-14
    • 2021-09-19
    • 2020-01-10
    • 2014-05-04
    • 1970-01-01
    • 2022-01-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多