[英]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.