问题描述
在我的MEAN Stack应用程序中使用 passport-google-oauth:"0.2.0"
(在此处找到: https://github.com/jaredhanson/passport-google-oauth ).当我运行该应用程序并尝试使用Google API登录时,将返回此错误
Using passport-google-oauth: "0.2.0"
in my MEAN Stack application (found here: https://github.com/jaredhanson/passport-google-oauth). When I run the application and attempt to sign in with a Google API this error is returned
- 那是一个错误.
错误:invalid_request
Error: invalid_request
缺少必需的参数:redirect_uri
Missing required parameter: redirect_uri
请求详细信息scope = https://www.googleapis.com/auth/plus.login response_type =代码redirect_uri =client_id = xxxx-xxxx.apps.googleusercontent.com
Request Details scope=https://www.googleapis.com/auth/plus.login response_type=code redirect_uri= client_id=xxxx-xxxx.apps.googleusercontent.com
重定向参数在这里 passport-init.js
var GOOGLE_CLIENT_ID ="xxx-xxx.apps.googleusercontent.com";var GOOGLE_CLIENT_SECRET ="xxxx";
var GOOGLE_CLIENT_ID = "xxx-xxx.apps.googleusercontent.com"; var GOOGLE_CLIENT_SECRET = "xxxx";
passport.use(新的GoogleStrategy({
clientID:GOOGLE_CLIENT_ID,
clientSecret:GOOGLE_CLIENT_SECRET,
callbackUrl:" http://127.0.0.1:3000/auth/google/oauth2callback "},功能(accessToken,refreshToken,配置文件,完成){已完成(null,profile);}));
passport.use(new GoogleStrategy({
clientID: GOOGLE_CLIENT_ID,
clientSecret: GOOGLE_CLIENT_SECRET,
callbackUrl: "http://127.0.0.1:3000/auth/google/oauth2callback" }, function(accessToken, refreshToken, profile, done){ done(null,profile); } ));
路由在此处 authenticate.js
router.get('/google/oauth2callback',护照.authenticate('google',{successRedirect:'/auth/success',failureRedirect:'/auth/failure'}),函数(req,res){res.redirect('/');});
router.get('/google/oauth2callback', passport.authenticate('google', { successRedirect: '/auth/success', failureRedirect: '/auth/failure' }) , function (req, res) {res.redirect('/');} );
我确定我缺少一些简单的东西,但是我不知道该问题中要添加哪些内容,这些内容将为您提供最佳信息.请询问,我会尽力回答您.这就是相关数据的感觉.
I am sure I am missing something simple, but I don't know what to add in this question that will give you the best information. Please ask and I will do my best to answer you. This is what feels like the pertinent data.
有趣的是,如果我手动添加callbackUrl,那么一切都会很好.我可以达到Google API的要求.然后,我可以选择允许"或拒绝"请求.
Funny thing is if I add the callbackUrl manually then everything works great. I can reach the Google API fine. Then I am given the choice to "allow" or "deny" the request.
推荐答案
定义GoogleStrategy时,JSON密钥应为callbackURL而不是callbackUrl(即大写URL).也有这个问题";-)
When defining the GoogleStrategy, the JSON key should be callbackURL instead of callbackUrl (i.e., capital URL). Had this 'issue' as well ;-)
这篇关于缺少必需的参数:带有passport-google-oauth的redirect_uri的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!