我正在尝试将用户重定向到我的应用中的 Google 授权页面。对于我的情况,我无法使用任何 Google API 模块。
我知道我可以这样格式化我的 res.redirect()
函数:
res.redirect('https://accounts.google.com/o/oauth2/auth?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcalendar.readonly&response_type=code&redirect_uri=https%3A%2F%2Flocalhost%3A3000%2Fauth&client_id=690512789525-g8dbv0s1jo80u5hvevptqapeqokq7ees.apps.googleusercontent.com&hl=en&from_login=1&as=-6cc9a02870d13e22&authuser=0')
但我更喜欢更干净的东西,我可以将查询参数保存在一个对象中。像这样的东西:
res.redirect({
uri: 'https://accounts.google.com/o/oauth2/auth,
scope: 'https://............etc',
response_type: 'code',
[...etc...]
})
将每个查询参数作为对象中的属性值对。
关于如何做到这一点有什么想法吗?
最佳答案
我认为你需要这样的东西 url.format(urlObj)
: https://nodejs.org/docs/latest/api/url.html#url_url_format_urlobj
关于javascript - 如何将查询参数添加到 node.js/express.js res.redirect 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30823857/