Discord OAuth2 redirect_uri 组件的问题

问题描述 投票:0回答:1

我目前正在为我的Web应用程序开发Discord OAuth2客户端。

无论我如何努力设置redirect_uri来使discord不发送错误,我都无法修复它,我一直得到这个消息。

Invalid OAuth2 redirect_uri : You can now close this tab.

Screenshot(抱歉第二行的外语)

我的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 typeredirect = (above) the url

谢谢大家的帮助。

编辑1:故意将redirect_uri设置为错误的URL,发送JSON消息说:"格式不对的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

node.js express oauth-2.0 discord
1个回答
0
投票

由于Discord是一个开放的网络应用,他们不能直接访问你的本地主机。这将导致你收到 "无效重定向URI "错误。

要解决这个问题,请设置一些端口转发,并向 Discord 提供您的 IP 地址,而不是 localhost。

© www.soinside.com 2019 - 2024. All rights reserved.