Node.js   发布时间:2022-04-24  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了node.js – redirect_uri的参数值无效:缺少方案:/ auth / google_auth_code / callback大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
编辑: @L_616_0@

我正在尝试从服务器端流程的授权代码获取Google的访问权限和刷新令牌.我在这里遵循Google的指南:https://developers.google.com/identity/sign-in/web/server-side-flow.

我使用护照和passport-google-authcode.

以下是节点应用的路由:

router.get('/auth/google_auth_code',passport.authenticate('google_authcode',{
        scope:
        [
            'https://www.googleapis.com/auth/calendar','profile','https://www.googleapis.com/auth/userinfo.email'
        ]
    }),function () {
        res.end();
    })

router.get('/auth/google_auth_code/callBACk',{
        failureRedirect: '/error'
    }),function (req,res) {
        // do something with req.user
        res.send('Hello');
    }
);

这是此策略的护照配置.

passport.use('google_authcode',new GoogleAuthCodeStrategy({
    clientID: 'my client id',clientSecret: 'my secret',callBACkURL: '/auth/google_auth_code/callBACk',// passReqToCallBACk: true
},function (accessToken,refreshToken,rawResponse,profile,donE) {
            // unable to get here
    }
));

发出身份验证请求时,Google会响应以下错误

{
  "error" : "invalid_request","error_description" : "Invalid parameter value for redirect_uri: Missing scheR_811_11845@e: /auth/google_auth_code/callBACk"
}

以下是我在Google控制台中设置的凭据:

node.js – redirect_uri的参数值无效:缺少方案:/ auth / google_auth_code / callback

此时我不知道还能做什么.我还尝试将passport.use中的回调URL更改为绝对URl.我肯定会得到一个有效的身份验证代码(它看起来像:4 / Mb2pcOyhYhziROyFHKH5pnzvUldYbAMMop9SJKbBHXQ).如果我能提供更多相关信息,请与我们联系.

谢谢,
山姆

编辑

我注意到我的网址以正斜杠结尾.我解决了这个问题,但我没有更新截图.

如果我使用完整的URL(例如`http://localhost:8080//auth/google_auth_code/callback),我会收到以下错误

{
  "error" : "unauthorized_client"
}

如果我使用完整的URL(例如`http://localhost:8080/auth/google_auth_code/callback),我会收到以下错误

{
  "error" : "redirect_uri_mismatch"
}

解决方法

似乎是passport-google bug,你可能会在这里看到它:
https://github.com/jaredhanson/passport-google-oauth/issues/21

他们在这个问题上的建议是什么:https://github.com/sqrrrl/passport-google-plus

它的开源程序如何工作,你必须自己解决它或找到另一个包.

大佬总结

以上是大佬教程为你收集整理的node.js – redirect_uri的参数值无效:缺少方案:/ auth / google_auth_code / callback全部内容,希望文章能够帮你解决node.js – redirect_uri的参数值无效:缺少方案:/ auth / google_auth_code / callback所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。