RafGDev

Untitled

May 5th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const koa = require("koa");
  2. const app = koa();
  3. const route = require("koa-route");
  4. const passport = require("koa-passport");
  5. const session = require("koa-session");
  6. app.keys = ['this is a secret'];
  7.  
  8.  
  9. var OpenIDStrategy = require('passport-openid').Strategy;
  10. var SteamStrategy = new OpenIDStrategy({
  11.  
  12.         providerURL: 'https://steamcommunity.com/openid',
  13.         stateless: true,
  14.  
  15.         returnURL: 'http://localhost:8888/returnSteamLogin',
  16.         realm: 'http://localhost:8888',
  17.     },
  18.  
  19.     function(identifier, done) {
  20.       process.nextTick(() => {
  21.         var user = {
  22.           identifier: identifier,
  23.           steamId: identifier.match(/\d+$/)[0]
  24.         };
  25.         return done(null, user);
  26.  
  27.       });
  28.    });
  29.  
  30. passport.serializeUser(function(user, done) {
  31.     done(null, user.steamId);
  32. });
  33. passport.deserializeUser(function(identifier, done) {
  34.     done(null, {
  35.         steamId: identifier
  36.     });
  37. });
  38.  
  39.  
  40. passport.use(SteamStrategy);
  41.  
  42. app.use(session(app));
  43.  
  44. app.use(passport.initialize());
  45. app.use(passport.session());
  46.  
  47.  
  48.  
  49. app.use(route.get("/signInThroughSteam", passport.authenticate("openid")));
  50.  
  51. app.use(route.get("/returnSteamLogin", passport.authenticate("openid"), function*() {
  52.     //I know cannot access the return URL because I get an error
  53. }));
  54.  
  55. app.listen(8888);
Add Comment
Please, Sign In to add comment