【发布时间】:2020-05-22 09:18:46
【问题描述】:
我目前正在为我的 Web 应用程序开发 Discord OAuth2 客户端。
无论我如何尝试设置 redirect_uri 以使 discord 不发送错误,我都无法修复它,并且我不断收到此消息:
OAuth2 redirect_uri 无效:您现在可以关闭此选项卡。
(对不起第二行的外语)
我的 redirect_uri 是:
const redirect = encodeURIComponent("http://localhost/callback");
(该网站存在于服务器上并且可以正常工作。)
**我尝试了很多组合,包括:
- 添加 https:// 而不是 http://
- 将.com 添加到域
- 在单词callback 之后添加一个斜杠
- 使用普通字符串而不是 encodeURIComponent
- 通过 Discord 开发者页面生成 oauth2 redirect_uri
**
唯一有效的是从 URL 参数中完全删除 redirect_uri,这使应用程序正常工作,但之后没有重定向到正确的位置;
(这是我的 oauth2 网址):
https://discordapp.com/api/oauth2/authorize?client_id=${id}&redirect_uri=${redirect}&response_type=code&scope=identify%20guilds%20email,
当id = client id in string type 和redirect = (above) the url
感谢您的帮助。
编辑 1:故意将 redirect_uri 设置为错误的 URL,发送一条 JSON 消息说“格式错误的 redirect_uri”。 (不是屏幕截图中可见的那个!)
编辑2:示例完整网址:
https://discordapp.com/oauth2/authorize?client_id=528972063096963140&redirect_uri=http%3A%2F%2Flocalhost%2Fdiscord%2Fcallback&response_type=code&scope=identify%20guilds%20email
【问题讨论】:
标签: node.js express oauth-2.0 discord