这个 javascript oauth 调用可以在 POSTMAN 中表示吗? (或 C#)

Can this javascript oauth call be represented in POSTMAN? (or c#)

我有一个 API 我正在尝试测试。他们发给我这个 javascript 所以我试着在下面模仿它。现在确定如何在邮递员中做到这一点

jQuery.ajax({
    dataType: 'json',
    type: 'POST',
    data: {grant_type: 'client_credentials'},
    url: 'http://192.168.240.6:9080/somecompany/auth/oauth/token',
    beforeSend: function( xhr ) {
      var clientID = 'c39692d9-8998-497f-8ea2-7503be9fc8c1',
          clientSecret = 'befb744f-37f5-491d-8d57-e8e5c1419f2e',
          authKey = btoa(clientID + ':' + clientSecret);
      xhr.setRequestHeader('Authorization', 'Basic ' + authKey);
    }

Postman 中的这个特定屏幕(Oauth 表单)不允许您通过“授权”header。代码片段中的请求表示 oauth client_credentials 流程中的一个步骤(参见 here), while the Postman form in the screenshot is the first one in (Authorization Code or Implict ones)(see here)。

如果您想完全复制示例中的内容,则必须在 Postman 中构造一个 POST 请求,手动添加示例中使用的 header 和有效负载。

但除此之外,您仍然会错过 javascript 示例中由 btoa 函数生成的编码字符串。如果您的目的只是手动测试它,您可以手动执行 btoa(clientID + ':' + clientSecret) 并将结果粘贴到 Postman header 的配置中。

ps:我强烈建议您阅读 Oauth 支持的不同授权流程。