how do i get the steamid and the details of the returned user ?
Closed this issue · 2 comments
DontAskM8 commented
This is my code
var express = require('express')
var fs = require('fs')
var path = require('path')
var SteamStrategy = require('passport-steam').Strategy
var passport = require('passport')
var session = require('express-session')
var app = express()
app.listen(80, function(){
console.log('Website Online')
})
app.use('/css', express.static(path.join(__dirname, 'css')))
app.use('/img', express.static(path.join(__dirname, 'img')))
app.use('/js', express.static(path.join(__dirname, 'js')))
app.use(passport.initialize())
app.use(passport.session())
app.use(session({
secret: 'your secret',
name: 'name of session id',
resave: true,
saveUninitialized: true}));
app.get('/', function(request, response){
fs.readFile('./html/main.html', function(error, data){
if(error) console.log("Error hosting help.html" + '\n' + err.message)
else response.write(data)
})
})
app.get('/help', function(request, response){
fs.readFile('./html/help.html', function(err, data){
if(err) console.log("Error hosting help.html" + '\n' + err.message)
else response.write(data)
})
})
app.get('/support', function(request, response){
fs.readFile('./html/support.html', function(err, data){
if(err) console.log("Error hosting support.html" + '\n' + err.message)
else response.write(data)
})
})
passport.serializeUser(function(user, done) {
done(null, user)
})
passport.deserializeUser(function(obj, done) {
done(null, obj)
})
passport.use(new SteamStrategy({
returnURL: 'http://localhost/login/return',
realm: 'http://localhost',
apiKey: 'xxxxxxxxxxxxxx'
},
function(identifier, profile, done) {
process.nextTick(function () {
profile.identifier = identifier;
return done(null, profile)
})
}
))
app.get('/login', passport.authenticate('steam'), function(request, response){
response.redirect('/')
})
app.get('/login/return', function(request, response){
response.redirect('/')
})
function ensureAuthenticated(req, res, next) {
if (req.isAuthenticated()) { return next(); }
}
app.get('/account', ensureAuthenticated, function(req, res){
res.write(req)
});
andrewda commented
req.user
contains the user object of a request.
DontAskM8 commented
But when i do console.log(req.user)
it says undefined
Update
Fixed it by reading the example code over and over again, i have to authenticate on the original and return url