liamcurry / passport-steam

Steam (OpenID) authentication strategy for Passport and Node.js.
MIT License
348 stars 104 forks source link

InternalOpenIDError: Failed to verify assertion #94

Closed haziqfiqri closed 5 years ago

haziqfiqri commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

Have you sorted your issue, @haziqfiqri ?

haziqfiqri commented 5 years ago

Yes i have :)

On Sat, 19 Oct 2019, 12:14 am Steven Agyekum, notifications@github.com wrote:

Have you sorted your issue, @haziqfiqri https://github.com/haziqfiqri ?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/liamcurry/passport-steam/issues/94?email_source=notifications&email_token=AG7ZYZOLXEX7R7XWLPPI7C3QPHOFHA5CNFSM4JB4OZNKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBU7PSA#issuecomment-543815624, or unsubscribe https://github.com/notifications/unsubscribe-auth/AG7ZYZJ3RSQM4AMSJCVWS23QPHOFHANCNFSM4JB4OZNA .y