Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InternalOpenIDError: Failed to verify assertion #94

Closed
haziqfiqri opened this issue Oct 17, 2019 · 3 comments
Closed

InternalOpenIDError: Failed to verify assertion #94

haziqfiqri opened this issue Oct 17, 2019 · 3 comments

Comments

@haziqfiqri
Copy link

I'm having issues with when an existence user trying to login back and update the database, non existence user login works alright as it will create one inside db, tried @Burnett01 solution here but doesnt work tho, still get the error. How can I solve this, Can someone kindly help?

node version: v10.16.0
passport: 0.4.0
passport-steam: 1.0.11

/routes/auth.js

function use_orginalurl(req, res, next){
    req.url = req.originalUrl;
    next();
}

router.get('/steam', use_orginalurl,
    passport.authenticate('steam', { failureRedirect: '/' }),
        function(req, res) {
        res.redirect('/');
});

router.get('/steam/return',
    function(req, res, next) {
        req.url = req.originalUrl;
        next();
    }, 
    passport.authenticate('steam', { failureRedirect: '/' }),
        function(req, res) {
        res.redirect('/');
});

app.js

const authRoutes = require('./routes/auth');
passport.use(new SteamStrategy({
    returnURL: 'http://localhost:3000/auth/steam/return',
    realm: 'http://localhost:3000/',
    apiKey: 'XXXXXXXXXXXXXXXXXXXXXXX'
    }, 
    function (identifier, profile, done){
        var steamId = identifier.match(/\d+$/)[0];
        var profileURL = 'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=' + 'XXXXXXXXXXXXXXXXXXXXXXX' + '&steamids=' + steamId;

        User.findOne({ steamId: steamId}, function(err, user){
            if(user){
                User.updateOne({ steamId }, {
                    $set: profile
                }, {
                    upsert: true
                }, (err) => {
                    if (err) {
                        console.log(err);
                    }
                });
            }
            else{
                request(profileURL, function (error, response, body){
                    if (!error && response.statusCode === 200) {
                        var data = JSON.parse(body);
                        var profile = data.response.players[0];

                        var user = new User();
                        user.username = profile.personaname;
                        user.profileURL = profile.profileurl;
                        user.profileImageURL = profile.avatarfull;
                        user.steamId = steamId;
                    
                        user.save(function(err){
                            done(err, user);
                        });
                    }
                    else{
                        done(err, null);
                    }
                });
            }
        });
}));
app.use('/auth', authRoutes);
@haziqfiqri
Copy link
Author

Lmao what was I thinking, here is the updated code

request(profileURL, function(err, response, body){
                        var data = JSON.parse(body);
                        var profile = data.response.players[0];
                        var user = {
                            username: profile.personaname,
                            profileURL: profile.profileurl,
                            profileImageURL: profile.avatarfull,
                            steamId: profile.steamid
                        }
                        User.findOneAndUpdate({ steamId: steamId }, user, {upsert: true, new: true, setDefaultsOnInsert: true}, function(err, newUser){
                            if (err) handleError(err);
                            done(null, newUser);
                        });
                    });

@Burnett01
Copy link

Have you sorted your issue, @haziqfiqri ?

@haziqfiqri
Copy link
Author

haziqfiqri commented Oct 18, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants