Adds Steam auth and API
This commit is contained in:
@ -172,6 +172,13 @@ Obtaining API Keys
|
|||||||
- Click **✔Register**
|
- Click **✔Register**
|
||||||
- Copy and paste *OAuth consumer key* and *OAuth consumer secret* keys into `config/secrets.js`
|
- Copy and paste *OAuth consumer key* and *OAuth consumer secret* keys into `config/secrets.js`
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
|
||||||
|
<img src="http://www.userlogos.org/files/logos/jumpordie/steam_01.png" width="200">
|
||||||
|
- Go to http://steamcommunity.com/dev/apikey
|
||||||
|
- Once signed in, enter your domainm agree to terms, and click **Register**
|
||||||
|
- Copy and paste *key* into `config.secrets.js`
|
||||||
|
|
||||||
Project Structure
|
Project Structure
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
6
app.js
6
app.js
@ -118,6 +118,8 @@ app.get('/api/aviary', apiController.getAviary);
|
|||||||
app.get('/api/paypal', apiController.getPayPal);
|
app.get('/api/paypal', apiController.getPayPal);
|
||||||
app.get('/api/paypal/success', apiController.getPayPalSuccess);
|
app.get('/api/paypal/success', apiController.getPayPalSuccess);
|
||||||
app.get('/api/paypal/cancel', apiController.getPayPalCancel);
|
app.get('/api/paypal/cancel', apiController.getPayPalCancel);
|
||||||
|
app.get('/api/steam', passportConf.isAuthorized, passportConf.isAuthorized, apiController.getSteam);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OAuth routes for sign-in.
|
* OAuth routes for sign-in.
|
||||||
@ -144,6 +146,10 @@ app.get('/auth/tumblr', passport.authorize('tumblr'));
|
|||||||
app.get('/auth/tumblr/callback', passport.authorize('tumblr', { failureRedirect: '/api' }), function(req, res) {
|
app.get('/auth/tumblr/callback', passport.authorize('tumblr', { failureRedirect: '/api' }), function(req, res) {
|
||||||
res.redirect('/api/tumblr');
|
res.redirect('/api/tumblr');
|
||||||
});
|
});
|
||||||
|
app.get('/auth/steam', passport.authenticate('steam'));
|
||||||
|
app.get('/auth/steam/callback', passport.authenticate('steam', { failureRedirect: '/login' }), function(req, res) {
|
||||||
|
res.redirect('/api/steam');
|
||||||
|
});
|
||||||
|
|
||||||
app.listen(app.get('port'), function() {
|
app.listen(app.get('port'), function() {
|
||||||
console.log("✔ Express server listening on port %d in %s mode", app.get('port'), app.settings.env);
|
console.log("✔ Express server listening on port %d in %s mode", app.get('port'), app.settings.env);
|
||||||
|
@ -6,6 +6,7 @@ var FacebookStrategy = require('passport-facebook').Strategy;
|
|||||||
var TwitterStrategy = require('passport-twitter').Strategy;
|
var TwitterStrategy = require('passport-twitter').Strategy;
|
||||||
var GitHubStrategy = require('passport-github').Strategy;
|
var GitHubStrategy = require('passport-github').Strategy;
|
||||||
var GoogleStrategy = require('passport-google-oauth').OAuth2Strategy;
|
var GoogleStrategy = require('passport-google-oauth').OAuth2Strategy;
|
||||||
|
var SteamStrategy = require('passport-steam').Strategy;
|
||||||
var User = require('../models/User');
|
var User = require('../models/User');
|
||||||
var secrets = require('./secrets');
|
var secrets = require('./secrets');
|
||||||
var _ = require('underscore');
|
var _ = require('underscore');
|
||||||
@ -37,7 +38,7 @@ passport.use(new LocalStrategy({ usernameField: 'email' }, function(email, passw
|
|||||||
* Sign in with Facebook.
|
* Sign in with Facebook.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
passport.use(new FacebookStrategy(secrets.facebook, function (req, accessToken, refreshToken, profile, done) {
|
passport.use(new FacebookStrategy(secrets.facebook, function(req, accessToken, refreshToken, profile, done) {
|
||||||
if (req.user) {
|
if (req.user) {
|
||||||
User.findOne({ $or: [{ facebook: profile.id }, { email: profile.email }] }, function(err, existingUser) {
|
User.findOne({ $or: [{ facebook: profile.id }, { email: profile.email }] }, function(err, existingUser) {
|
||||||
if (existingUser) {
|
if (existingUser) {
|
||||||
@ -201,6 +202,47 @@ passport.use(new GoogleStrategy(secrets.google, function(req, accessToken, refre
|
|||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sign in with Steam.
|
||||||
|
*/
|
||||||
|
|
||||||
|
passport.use(new SteamStrategy(secrets.steam, function(req, identifier, profile, done) {
|
||||||
|
identifier = identifier.match('http://steamcommunity.com/openid/id/([0-9]{17,25})');
|
||||||
|
var steam_id = identifier[1];
|
||||||
|
if (req.user) {
|
||||||
|
User.findOne({ steam: steam_id }, function(err, existingUser) {
|
||||||
|
if (existingUser) {
|
||||||
|
req.flash('errors', { msg: 'There is already a Steam account that belongs to you. Sign in with that account or delete it, then link it with your current account.' });
|
||||||
|
done(err);
|
||||||
|
} else {
|
||||||
|
User.findById(req.user.id, function(err, user) {
|
||||||
|
user.steam = steam_id;
|
||||||
|
user.tokens.push({ kind: 'steam', accessToken: steam_id });
|
||||||
|
user.save(function(err) {
|
||||||
|
req.flash('info', { msg: 'Steam account has been linked.' });
|
||||||
|
done(err, user);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
} else {
|
||||||
|
User.findOne({ steam: steam_id }, function(err, existingUser) {
|
||||||
|
if (existingUser) return done(null, existingUser);
|
||||||
|
var user = new User();
|
||||||
|
user.steam = steam_id;
|
||||||
|
user.tokens.push({ kind: 'steam', steam_id: steam_id });
|
||||||
|
user.save(function(err) {
|
||||||
|
done(err, user);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sign in with Tumblr.
|
||||||
|
*/
|
||||||
|
|
||||||
passport.use('tumblr', new OAuthStrategy({
|
passport.use('tumblr', new OAuthStrategy({
|
||||||
requestTokenURL: 'http://www.tumblr.com/oauth/request_token',
|
requestTokenURL: 'http://www.tumblr.com/oauth/request_token',
|
||||||
accessTokenURL: 'http://www.tumblr.com/oauth/access_token',
|
accessTokenURL: 'http://www.tumblr.com/oauth/access_token',
|
||||||
@ -220,6 +262,10 @@ passport.use('tumblr', new OAuthStrategy({
|
|||||||
}
|
}
|
||||||
));
|
));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sign in with Foursquare.
|
||||||
|
*/
|
||||||
|
|
||||||
passport.use('foursquare', new OAuth2Strategy({
|
passport.use('foursquare', new OAuth2Strategy({
|
||||||
authorizationURL: 'https://foursquare.com/oauth2/authorize',
|
authorizationURL: 'https://foursquare.com/oauth2/authorize',
|
||||||
tokenURL: 'https://foursquare.com/oauth2/access_token',
|
tokenURL: 'https://foursquare.com/oauth2/access_token',
|
||||||
|
@ -12,6 +12,9 @@ var foursquare = require('node-foursquare')({ secrets: secrets.foursquare });
|
|||||||
var Github = require('github-api');
|
var Github = require('github-api');
|
||||||
var Twit = require('twit');
|
var Twit = require('twit');
|
||||||
var paypal = require('paypal-rest-sdk');
|
var paypal = require('paypal-rest-sdk');
|
||||||
|
var steam = require('steam-web');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GET /api
|
* GET /api
|
||||||
@ -332,3 +335,24 @@ exports.getPayPalCancel = function(req, res, next) {
|
|||||||
canceled: true
|
canceled: true
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET /api/steam
|
||||||
|
* Steam API example.
|
||||||
|
*/
|
||||||
|
|
||||||
|
exports.getSteam = function(req, res) {
|
||||||
|
var S = new steam({
|
||||||
|
apiKey: secrets.steam.apiKey
|
||||||
|
});
|
||||||
|
|
||||||
|
S.getPlayerSummaries({
|
||||||
|
steamids: [ req.user.steam ],
|
||||||
|
callback: function(err, data) {
|
||||||
|
res.render('api/steam', {
|
||||||
|
title: 'Steam Web API',
|
||||||
|
players: data.response.players,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
@ -2,13 +2,15 @@ var mongoose = require('mongoose');
|
|||||||
var bcrypt = require('bcrypt-nodejs');
|
var bcrypt = require('bcrypt-nodejs');
|
||||||
|
|
||||||
var userSchema = new mongoose.Schema({
|
var userSchema = new mongoose.Schema({
|
||||||
email: { type: String, unique: true },
|
email: { type: String, unique: true, sparse: true },
|
||||||
password: String,
|
password: String,
|
||||||
|
|
||||||
facebook: { type: String, unique: true, sparse: true },
|
facebook: { type: String, unique: true, sparse: true },
|
||||||
twitter: { type: String, unique: true, sparse: true },
|
twitter: { type: String, unique: true, sparse: true },
|
||||||
google: { type: String, unique: true, sparse: true },
|
google: { type: String, unique: true, sparse: true },
|
||||||
github: { type: String, unique: true, sparse: true },
|
github: { type: String, unique: true, sparse: true },
|
||||||
|
steam: { type: String, unique: true, sparse: true },
|
||||||
|
|
||||||
tokens: Array,
|
tokens: Array,
|
||||||
|
|
||||||
profile: {
|
profile: {
|
||||||
|
@ -28,6 +28,8 @@
|
|||||||
"twit": "~1.1.12",
|
"twit": "~1.1.12",
|
||||||
"underscore": "~1.5.2",
|
"underscore": "~1.5.2",
|
||||||
"paypal-rest-sdk": "~0.6.4",
|
"paypal-rest-sdk": "~0.6.4",
|
||||||
"connect-mongo": "~0.4.0"
|
"connect-mongo": "~0.4.0",
|
||||||
|
"passport-steam": "~0.1.3",
|
||||||
|
"steam-web": "~0.2.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,3 +35,7 @@ block content
|
|||||||
a(href='/api/scraping') Web Scraping
|
a(href='/api/scraping') Web Scraping
|
||||||
li
|
li
|
||||||
a(href='/api/paypal') PayPal
|
a(href='/api/paypal') PayPal
|
||||||
|
li
|
||||||
|
a(href='/api/steam')
|
||||||
|
i.fa.fa-lock
|
||||||
|
| Steam
|
||||||
|
23
views/api/steam.jade
Normal file
23
views/api/steam.jade
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
extends ../layout
|
||||||
|
|
||||||
|
block content
|
||||||
|
.page-header
|
||||||
|
h2
|
||||||
|
i.fa.fa-gamepad
|
||||||
|
| Steam Web API
|
||||||
|
|
||||||
|
.btn-group.btn-group-justified
|
||||||
|
a.btn.btn-primary(href='https://developer.valvesoftware.com/wiki/Steam_Web_API', target='_blank')
|
||||||
|
i.fa.fa-check-square-o
|
||||||
|
| Overview
|
||||||
|
|
||||||
|
h4 Steam Players
|
||||||
|
|
||||||
|
ul.list-unstyled
|
||||||
|
for player in players
|
||||||
|
li
|
||||||
|
.panel.panel-default
|
||||||
|
.panel-body
|
||||||
|
.clearfix
|
||||||
|
img.pull-left(src='#{player.avatarfull}', style='margin-right: 10px')
|
||||||
|
=player.personaname
|
Reference in New Issue
Block a user