Comments (9)
I guess you just need to:
- Create a user schema using mongoose, which will hold your users data. Be sure that schema has specific fields for
username
and other steam account data that can be useful in your app (such asprofileUrl
,profileImageUrl
,steamId
, etc). - When the user logs in and given the fact the login was successful, just check if the user exists (for example, by searching for its
steamId
like:
passport.use(new SteamStrategy({
returnURL: 'http://localhost:3000/auth/steam/return',
realm: 'http://localhost:3000/',
apiKey: 'your steam API key'
}, function (identifier, profile, done) {
var steamId = identifier.match(/\d+$/)[0];
var profileURL = 'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=' + 'your steam API key' + '&steamids=' + steamId;
User.findOne({ steamId: steamId }, function (err, user) {
if (user) { // If the user already exists
// Edit fields that might be outdated such as steam user image...
}
else { // If the user does not exist create a new one
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.avatarmedium;
user.steamId = steamId;
user.save(function (err) {
done(err, user);
});
} else {
done(error, null);
}
});
}
});
Of course this is just a starting point, you'll have to adjust this according to your needs.
from passport-steam.
Yep, @pgrodrigues just about nailed it. That's exactly what you'll need to get it working on a basic level. You might be able to lighten up the code a little by just using the update()
method's upsert
option, which will edit a document or create one if it does not exist. For example:
User.update({ steamid }, {
$set: profile
}, {
upsert: true
}, (err) => {
if (err) {
console.log(err);
}
});
This will update a document with the steamid
field equal to the steamid
variable (using some ES6 magic on that first line... makes stuff look cleaner). Then we override the existing document with our updated profile, and, if the document does not exist, it will be created thanks to our upsert: true
option.
from passport-steam.
You're right @andrewda. Either update()
or findOneAndUpdate()
with upsert: true
is the way to go.
from passport-steam.
Correct me if I'm wrong, but passport-local-mongoose
seems to be a way to easily store usernames and hashed passwords in your database. The purpose of using passport-steam
is to not have to store passwords in your database – users login on the Steam servers instead.
It sounds like you might be looking for a session store, though that is not what passport-local-mongoose
does. If that's the case, checkout the Express session store documentation and connect-mongo
.
Tell me if none of this is what you're asking, but hope this helps!
from passport-steam.
I'm reading these, but to make it simple. I would like to store them as a user in the database once they've logged in with steam. This way other things can be associated with them like forum posts, comments, etc.
Sorry if I was being unclear
from passport-steam.
Ah okay, I understand. There is no module right now AFAIK that is taking on this task, but it's not difficult to accomplish by yourself. It shouldn't take more than ~20 lines to store all of a user's data in a MongoDB/Mongoose database.
from passport-steam.
Would you mind hinting me towards the right direction to accomplish this? It would be extremely helpful.
from passport-steam.
Thanks everyone, you have been a huge help!
from passport-steam.
No problem :) issue can be closed.
from passport-steam.
Related Issues (20)
- Cant connect passport-steam with nest js HOT 1
- Dynamic return url HOT 3
- Passing state to steam & back HOT 4
- unauthorized
- Passport and React Native
- Send params with auth request
- Infinite redirect HOT 1
- Passing custom variable(s) to Steam HOT 1
- [QUESTION] Usage with NestJS and TypeScript HOT 2
- Potential vulnerability
- Consider using certified OpenID library HOT 2
- Unable to pass req.isAuthenticated() check in backend api HOT 3
- Failed to discover OP endpoint URL HOT 1
- Failed to discover OP endpoint URL
- User creation
- What I should do with Validate? HOT 2
- NEW EXPLOIT. Need to pass some token to return_url HOT 6
- [question] Help with Storing HOT 3
- InternalOpenIDError: Failed to verify assertion HOT 3
- InternalOpenIDError: Failed to discover OP endpoint URL HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from passport-steam.