【问题标题】:Unable to reach to the redirecting URL while using passport-google-oauth20使用 passport-google-oauth20 时无法访问重定向 URL
【发布时间】:2018-12-02 22:07:09
【问题描述】:

我刚开始学习 OAuth。我正在将passport-google-oauth20 与node.js 一起使用。以下是我项目的 passport-setup.js 文件中的代码。

const passport = require('passport');
const GoogleStrategy = require('passport-google-oauth20');
const keys = require('./keys')

passport.use(
    new GoogleStrategy({
        //options for google strategy
        callbackURL:'https://localhost:3000/auth/google/redirect',
        clientID:keys.google.clientID,
        clientSecret:keys.google.clientSecret
    }, function(){
        //passport callback function
})
);

我项目的 auth-route.js 文件中的代码

const router = require('express').Router();
const passport = require('passport');

//auth login
router.get('/login', function(req,res){
    res.render('login');
});

//auth logout
router.get('/logout', function(req,res){
    //have to handle with passport
    res.send('Logging out');
});

//auth with google
router.get('/google', passport.authenticate('google',{
    scope:['profile']
}));

//callback route for google
router.get('/google/redirect', passport.authenticate('google'), 
    function(req,res){
        res.send('You logged in');
});

module.exports = router;

可参考完整代码@https://github.com/Ayush-Porwal/OAuth-learning.git

重定向 URL 有问题。当 callbackURL 的值为“https://localhost:3000/auth/google/redirect”时,浏览器会将我引导至 OAuth 同意屏幕。但是,当我尝试登录后,浏览器(chrome)给了我一个错误/消息,如屏幕截图所示。

在火狐浏览器上,消息如图(添加只是因为错误消息不同)

当 callbackURL 保持“/auth/google/redirect”的值时(我认为这两个值应该给出相同的结果)。浏览器给出的错误为

这是我在谷歌开发者网站上的应用中输入的 URI 的屏幕截图。

我尝试了几件事,例如稍微更改代码等,但我无法意识到问题出在哪里。请帮忙。

【问题讨论】:

    标签: node.js oauth-2.0 google-oauth


    【解决方案1】:

    过程不完整。我现在已经完成了我的项目,并且我已经写了一个相同的答案。请从这里跟进我对Google Oauth giving code redeemed error的回答

    【讨论】:

    • 您可以在此处发布该答案,这会有所帮助。
    猜你喜欢
    • 1970-01-01
    • 2019-06-08
    • 2018-07-04
    • 2020-07-12
    • 2019-03-02
    • 2018-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多