缺less必要的参数:redirect_uri与passport-google-oauth
在我的MEAN Stack应用程序中使用passport-google-oauth: "0.2.0"
(在这里find: https : //github.com/jaredhanson/passport-google-oauth )。 当我运行应用程序并尝试使用Google APIlogin时,将返回此错误
- 这是一个错误。
错误:invalid_request
缺less所需的参数:redirect_uri
请求详细信息scope = https://www.googleapis.com/auth/plus.login response_type = code redirect_uri = client_id = xxxx-xxxx.apps.googleusercontent.com
redirect参数在这里passport-init.js
var GoogleStrategy = require('passport-google-oauth')。OAuth2Strategy;
var GOOGLE_CLIENT_ID =“xxx-xxx.apps.googleusercontent.com”; var GOOGLE_CLIENT_SECRET =“xxxx”;
passport.use(新的GoogleStrategy({
客户ID:GOOGLE_CLIENT_ID,
clientSecret:GOOGLE_CLIENT_SECRET,
callbackUrl:“ http://127.0.0.1:3000/auth/google/oauth2callback ”},函数(accessToken,refreshToken,profile,done){done(null,profile); }));
这里的路由是authenticate.js
router.get('/ google',passport.authenticate('google',{scope:[' https://www.googleapis.com/auth/plus.login ']}),function(req,res){} );
router.get('/ google / oauth2callback',passport.authenticate('google',{successRedirect:'/ auth / success',failureRedirect:'/ auth / failure'}),function(req,res){res.redirect ('/');});
我相信我错过了一些简单的东西,但是我不知道要在这个问题中添加什么,这会给你提供最好的信息。 请问,我会尽力回答你。 这就是相关数据的感觉。
有趣的是,如果我手动添加callbackUrl,那么一切都很好。 我可以达到Google API的罚款。 然后,我可以select“允许”或“拒绝”请求。
在定义GoogleStrategy时,JSON键应该是callbackURL,而不是callbackUrl(即大写的URL)。 有这个“问题”以及;-)
我有一个使用相同策略的工作示例。 由于我没有得到这个错误,不能确定问题是什么,但我想build议你检查以下内容:
-
添加到您的谷歌策略创build(新的GoogleStrategy({…}))范围:
-
确保您的谷歌API是在开发API控制台正确configuration。 特别:
- 在API和auth |下 凭证| OAuth同意屏幕 – 所有必需的url。
- 在API和auth |下 凭证 – 寻找你的网页API客户端,并看到你授权所有相关的URI。 如果调用来自或redirect到本节未列出的页面,auth将不起作用。