我目前正在为我的网络应用程序开发Discord OAuth2客户端。
无论我怎样尝试设置redirect_uri以使discord不发送错误,我都不能解决它,我一直收到这个消息:
Invalid OAuth2 redirect_uri : You can now close this tab.
(对不起第二行出现了外文)
我的redirect_uri是:
const redirect = encodeURIComponent("http://localhost/callback");
(该网站在服务器上存在并且运行正常。)
** 我尝试了很多组合,包括: - 在域名前添加https://而不是http:// - 在域名后添加.com - 在单词callback后添加斜杠 - 使用普通字符串而不是encodeURIComponent - 通过Discord Developer页面生成oauth2 redirect_uri **
唯一有效的方法是完全从URL参数中删除redirect_uri,这让应用程序工作,但之后没有重定向到正确的位置;
(这是我的oauth2 url):
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 = (上面)的url
感谢任何帮助。
编辑1:故意将redirect_uri设置为错误的URL,会发送一个JSON消息,内容为“Badly formatted redirect_uri.”(不是屏幕截图上可见的那个!)
编辑2:完整的示例URL:
https://discordapp.com/oauth2/authorize?client_id=528972063096963140&redirect_uri=http%3A%2F%2Flocalhost%2Fdiscord%2Fcallback&response_type=code&scope=identify%20guilds%20email