我正在尝试制作一个缩放oauth2.0应用程序。为此,我创建了一个访问zoom api的后端路由。我正在尝试执行定位到https://marketplace.zoom.us/docs/guides/auth/oauth的步骤1和2,但步骤2遇到了问题,步骤2是获取令牌的post请求。下面是我的代码:
router.get('/zoom', auth, async (req, res) => {
if (req.query.code) {
const url = `https://zoom.us/oauth/token?grant_type=authorization_code&code=${req.query.code}&redirect_uri=${CLIENT_HOME_PAGE_URL}`;
const headers = {
'Content-Type': 'application/json',
Authorization:
'Basic clientid:clientsecret'
};
try {
const res = await axios.post(url, null, { headers: headers });
console.log(res);
} catch (err) {
console.error(err.message);
return res.status(500).send('Sever Error');
}
}
res.redirect(
`https://zoom.us/oauth/authorize?response_type=code&client_id=${ZOOM_CLIENT_ID}&redirect_uri=${ZOOM_REDIRECT_URI}`
);
});现在,我只想打印数据。ZOOM_REDIRECT_URI指向相同的'/zoom'路由,并且clientid:clientsecret被实际客户端id和密码的base64string版本替换。我可以被重定向到https://zoom.us/oauth/authorize,它会将我重定向回/zoom,并尝试向url发出post请求,但post请求失败,状态为403。我的代码出了什么问题?
发布于 2020-07-16 06:56:25
您可能希望尝试使用请求正文中编码为表单url的数据发送POST,这是OAuth标准:
const formData = new URLSearchParams();
formData.append('grant_type', 'authorization_code');
formData.append('code', 'some_code');
formData.append('redirect_uri', 'some_redirect_uri');
const options = {
url: this._configuration.tokenEndpoint,
method: 'POST',
data: formData,
headers: {
'content-type': 'application/x-www-form-urlencoded',
'accept': 'application/json',
},
};
const response = await axios.request(options);奇怪的是,Zoom文档显示了一个带有查询参数的POST --可能是文档问题……
https://stackoverflow.com/questions/62868194
复制相似问题