Guest User

Untitled

a guest
Feb 19th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.23 KB | None | 0 0
  1. var bodyParser = require("body-parser");
  2. var routes1 = require("./routes/routes.js");
  3.  
  4. var app = express();
  5.  
  6. app.use(bodyParser.json());
  7. app.use(bodyParser.urlencoded({ extended: true }));
  8.  
  9. // **Steam sign-in process**
  10. routes1(app);
  11. // **Steam sign-in process**
  12.  
  13.  
  14. var port = 4000;
  15. var server = app.listen(port);
  16. console.log("listening on port " + port);
  17.  
  18. const express = require("express");
  19. var app = express();
  20. const session = require("express-session");
  21. const FirebaseStore = require("connect-session-firebase")(session);
  22. const firebase = require("firebase-admin");
  23. const ref = firebase.initializeApp({
  24. credential: firebase.credential.cert("./node/serviceAccountSettings.json"),
  25. databaseURL: "https://"firebase".firebaseio.com"
  26. });
  27. var steamUserID;
  28. // ***********STEAM AUTH BEGINS**************
  29. var steamAuth = app => {
  30. app.use(
  31. session({
  32. store: new FirebaseStore({
  33. database: ref.database()
  34. }),
  35. secret: "big boy",
  36. resave: true,
  37. saveUninitialized: true
  38. })
  39. );
  40.  
  41. var OpenIDStrategy = require("passport-openid").Strategy;
  42. var SteamStrategy = new OpenIDStrategy(
  43. {
  44. // OpenID provider configuration
  45. providerURL: "http://steamcommunity.com/openid",
  46. stateless: true,
  47. // How the OpenID provider should return the client to us
  48. returnURL: "http://localhost:4000/auth/openid/return",
  49. realm: "http://localhost:4000/"
  50. },
  51. function(identifier, done) {
  52. process.nextTick(function() {
  53. var user = {
  54. identifier: identifier,
  55. steamId: identifier.match(/d+$/)[0]
  56. };
  57. return done(null, user);
  58. });
  59. }
  60. );
  61.  
  62. var passport = require("passport");
  63. passport.use(SteamStrategy);
  64.  
  65. passport.serializeUser(function(user, done) {
  66. done(null, user.identifier);
  67. });
  68.  
  69. passport.deserializeUser(function(identifier, done) {
  70. done(null, {
  71. identifier: identifier,
  72. steamId: identifier.match(/d+$/)[0]
  73. });
  74. });
  75.  
  76. app.use(passport.initialize());
  77. app.use(passport.session());
  78.  
  79. app.post("/auth/openid", passport.authenticate("openid"));
  80.  
  81. app.get("/auth/openid/return", passport.authenticate("openid"), function(
  82. request,
  83. response
  84. ) {
  85. if (request.user) {
  86. response.redirect("/");
  87. } else {
  88. response.redirect("/?failed");
  89. }
  90. });
  91.  
  92. app.post("/auth/logout", function(request, response) {
  93. request.logout();
  94. response.redirect(request.get("Referer") || "http://localhost:4000");
  95. });
  96.  
  97. app.get("/", function(request, response) {
  98. response.write("<!DOCTYPE html>");
  99. if (request.user) {
  100. response.write(
  101. (request.session.passport &&
  102. console.log("SteamId: " + request.user.steamId)) ||
  103. ""
  104. );
  105. // sets the steamId to a variable
  106. steamUserID = request.user.steamId;
  107.  
  108.  
  109. // **Kick off the API**
  110. appRouter(app);
  111. //********** */
  112.  
  113. console.log("steamUserID: ", steamUserID);
  114. response.write('<form action="/auth/logout" method="post">');
  115. response.write('<input type="submit" value="Log Out"/></form>');
  116. } else {
  117. if (request.query.steamid) {
  118. }
  119.  
  120. }
  121. response.send();
  122. });
  123. };
  124. // **********STEAM AUTH ENDS**************
  125.  
  126. // ********SteamID API********
  127.  
  128.  
  129.  
  130. function appRouter(app) {
  131. app.get("/", function(req, res) {
  132. res.status(200).send();
  133. });
  134.  
  135. app.get("/steamId", function(req, res) {
  136. var data = {
  137. signInID: steamUserID
  138. };
  139. res.status(200).send(data);
  140. });
  141. }
  142. // *********API ENDS******************
  143.  
  144. module.exports = steamAuth;
  145.  
  146. <div>
  147. <input id="steamButton" ng-click="$scope.signin()" name="submit" type="image" src="http://steamcommunity-a.akamaihd.net/public/images/signinthroughsteam/sits_small.png"
  148. alt="Sign in through Steam">
  149. </form>
  150. </div>
  151.  
  152. LoginCtrl.js
  153.  
  154. angular
  155. .module("steamApp")
  156. .controller("LoginCtrl", function($scope, $window, $rootScope) {
  157. $scope.test = "hello";
  158. console.log($scope.test)
  159.  
  160.  
  161. $scope.signin = function (){
  162. $http.get('http://localhost:4000').success(function(data){
  163. console.log(data);
  164. });
  165. };
  166.  
  167. });
  168.  
  169. angular.module("steamApp", ["ngRoute"]).config(
  170. function($routeProvider) {
  171. $routeProvider
  172. .when("/", {
  173. template: "partials/navbar.html",
  174. controller: "LoginCtrl"
  175. })
  176. });
Add Comment
Please, Sign In to add comment