node.js - redirect_uri_mismatch: http://localhost:4500/AUTH/auth/google/callback,不匹配
问题描述
这个问题有很多问题,我都阅读了,但没有看到任何类似的问题。在我的情况下,“auth”是前置的。这是我在应用程序设置中注册为回调 url
http://localhost:4500/auth/google/callback
这是 passport.js 配置:
passport.use(
new GoogleStrategy.Strategy(
{
clientID: process.env.GOOGLE_CLIENT_ID!,// "!" is typescript
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
callbackURL: "auth/google/callback",
},
async (accessToken, refreshToken, profile, done) => {
const existingUser = await User.findOne({ googleId: profile.id });
if (existingUser) {
done(undefined, existingUser);
}
const user = await new User({ googleId: profile.id }).save();
done(undefined, user);
}
)
);
以下是路线:
export const authRoutes = (app: Application) => {
//with passing "google" passport knows that it will use GoogleStrategy
app.get(
"/auth/google",
passport.authenticate("google", { scope: ["profile", "email"] })
);
app.get("/auth/google/callback", passport.authenticate("google"));
app.get("/auth/current_user", (req: Request, res: Response) => {
res.send(req.user);
});
app.get("/auth/logout", (req: Request, res: Response) => {
req.logout();
res.json({ user: req.user });
});
};
这是错误消息:
错误 400:redirect_uri_mismatch 请求中的重定向 URI http://localhost:4500/auth/auth/google/callback 与授权给 OAuth 客户端的重定向 URI 不匹配。要更新授权的重定向 URI,请访问:https://console.developers.google.com/apis/credentials/oauthclient/${your_client_id}?project=${your_project_number}
解决方案
转到谷歌开发者控制台。确保您正在检查正确的项目和正确的客户。这必须是您在代码中使用的那个。然后加
http://localhost:4500/auth/auth/google/callback
作为重定向 URI。
如果谷歌说它没有设置它没有设置,你需要仔细检查端口和协议是否重要,即使是尾随 / 也会使其匹配失败。
推荐阅读
- reactjs - ReactTestUtils.Simulate.mouseDown
- powerbi - 尝试根据单元格填充列的一部分
- css - 类型'string |上不存在属性按钮基本 数字'
- json - Facebook Pixel 脚本覆盖全局 JSON
- python - 在 python 中需要帮助“导入随机”
- javascript - 如何绕过 xss 客户端过滤器
- uml - 如何为同一用例创建具有多个选项的 UML 用例图?
- google-cloud-trace - GCP Cloud trace/Opentelemetry/Koa 没有按我预期的那样工作
- vb.net - 使用 DragDrop VB.Net 复制文件
- python-3.x - 在python dict中计算相等的值(碰撞)