简体   繁体   English

如何使用 simple-oauth2 库发出请求 application/x-www-form-urlencoded?

[英]how to use the simple-oauth2 library to make request application/x-www-form-urlencoded?

i have some code which perfectly work through mac terminal and giving me token from website我有一些代码可以完美地通过 mac 终端工作并从网站给我令牌

curl -XPOST "https://link.com/oauth/access_token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: 1.0" \
--data-urlencode "grant_type=client_credentials" \
--data-urlencode "client_id=myawesomeapp" \
--data-urlencode "client_secret=abc123" \
--data-urlencode "scope=read write"

I want to do request through nodejs without curl request.我想在没有 curl 请求的情况下通过 nodejs 进行请求。 website giving link on npm library simple-oauth2, but my code does not work.网站在 npm 库 simple-oauth2 上提供链接,但我的代码不起作用。

my not working version of this我不工作的版本

const credentials = {
  client: {
    id: 'myawesomeapp',
    secret: 'abc123'
  },
  auth: {
    tokenHost: 'https://link.com',
    tokenPath: '/oauth/access_token'
  },
  http: {
    'headers.authorization': 'headers.Accept = application/x-www-form-urlencoded'
  }
};


 oauth2 = oauth2.create(credentials);

 oauth2.accessToken.create()

If it's an x-www-form-urlencoded content type, you'll probably need to also update the authorisation method in your options to form (its default is header ).如果它是 x-www-form-urlencoded 内容类型,您可能还需要更新表单选项中的授权方法(其默认值为header )。 Ie IE

const credentials = {
    /*
       your existing config
    */
    options: {
        authorizationMethod: 'body'
    }
}

Hopefully that should do the trick...希望这应该可以解决问题......

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用“内容类型”:“ application / x-www-form-urlencoded”发出发布请求? - How to make a Post request with “content type”: “application/x-www-form-urlencoded”? 如何使发布请求具有bas ic auth和内容类型x-www-form-urlencoded - how to make post request baswith ic auth and content type x-www-form-urlencoded 如何在nodejs中支持application / json,application / x-www-form-urlencoded和multipart / form-data的请求或响应主体 - how to support request or response bodies for application/json, application/x-www-form-urlencoded and multipart/form-data in nodejs 使用 axios 发出 x-www-form-urlencoded 请求 - Making a x-www-form-urlencoded request with axios 具有 application/x-www-form-urlencoded 格式的 Node.js Axios POST 请求? - Node.js Axios POST request with application/x-www-form-urlencoded format? 使用application / x-www-form-urlencoded使用node.js在发布请求中发送数组 - Send Array in post request using node.js using application/x-www-form-urlencoded 通过 @IsInt() 验证 application/x-www-form-urlencoded 请求类型 - Pass @IsInt() validation for application/x-www-form-urlencoded request type 包含ascii字符的POST请求[x-www-form-urlencoded] - POST request containing ascii characters [x-www-form-urlencoded] 解析ExpressJS中的application / x-www-form-urlencoded - Parsing application/x-www-form-urlencoded in Expressjs 如何使用 Axios 在 application/x-www-form-urlencoded 中编码 JSON 数据? - How to encode JSON data in application/x-www-form-urlencoded using Axios?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM