Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var bodyParser = require("body-parser");
- var routes1 = require("./routes/routes.js");
- var app = express();
- app.use(bodyParser.json());
- app.use(bodyParser.urlencoded({ extended: true }));
- // **Steam sign-in process**
- routes1(app);
- // **Steam sign-in process**
- var port = 4000;
- var server = app.listen(port);
- console.log("listening on port " + port);
- const express = require("express");
- var app = express();
- const session = require("express-session");
- const FirebaseStore = require("connect-session-firebase")(session);
- const firebase = require("firebase-admin");
- const ref = firebase.initializeApp({
- credential: firebase.credential.cert("./node/serviceAccountSettings.json"),
- databaseURL: "https://"firebase".firebaseio.com"
- });
- var steamUserID;
- // ***********STEAM AUTH BEGINS**************
- var steamAuth = app => {
- app.use(
- session({
- store: new FirebaseStore({
- database: ref.database()
- }),
- secret: "big boy",
- resave: true,
- saveUninitialized: true
- })
- );
- var OpenIDStrategy = require("passport-openid").Strategy;
- var SteamStrategy = new OpenIDStrategy(
- {
- // OpenID provider configuration
- providerURL: "http://steamcommunity.com/openid",
- stateless: true,
- // How the OpenID provider should return the client to us
- returnURL: "http://localhost:4000/auth/openid/return",
- realm: "http://localhost:4000/"
- },
- function(identifier, done) {
- process.nextTick(function() {
- var user = {
- identifier: identifier,
- steamId: identifier.match(/d+$/)[0]
- };
- return done(null, user);
- });
- }
- );
- var passport = require("passport");
- passport.use(SteamStrategy);
- passport.serializeUser(function(user, done) {
- done(null, user.identifier);
- });
- passport.deserializeUser(function(identifier, done) {
- done(null, {
- identifier: identifier,
- steamId: identifier.match(/d+$/)[0]
- });
- });
- app.use(passport.initialize());
- app.use(passport.session());
- app.post("/auth/openid", passport.authenticate("openid"));
- app.get("/auth/openid/return", passport.authenticate("openid"), function(
- request,
- response
- ) {
- if (request.user) {
- response.redirect("/");
- } else {
- response.redirect("/?failed");
- }
- });
- app.post("/auth/logout", function(request, response) {
- request.logout();
- response.redirect(request.get("Referer") || "http://localhost:4000");
- });
- app.get("/", function(request, response) {
- response.write("<!DOCTYPE html>");
- if (request.user) {
- response.write(
- (request.session.passport &&
- console.log("SteamId: " + request.user.steamId)) ||
- ""
- );
- // sets the steamId to a variable
- steamUserID = request.user.steamId;
- // **Kick off the API**
- appRouter(app);
- //********** */
- console.log("steamUserID: ", steamUserID);
- response.write('<form action="/auth/logout" method="post">');
- response.write('<input type="submit" value="Log Out"/></form>');
- } else {
- if (request.query.steamid) {
- }
- }
- response.send();
- });
- };
- // **********STEAM AUTH ENDS**************
- // ********SteamID API********
- function appRouter(app) {
- app.get("/", function(req, res) {
- res.status(200).send();
- });
- app.get("/steamId", function(req, res) {
- var data = {
- signInID: steamUserID
- };
- res.status(200).send(data);
- });
- }
- // *********API ENDS******************
- module.exports = steamAuth;
- <div>
- <input id="steamButton" ng-click="$scope.signin()" name="submit" type="image" src="http://steamcommunity-a.akamaihd.net/public/images/signinthroughsteam/sits_small.png"
- alt="Sign in through Steam">
- </form>
- </div>
- LoginCtrl.js
- angular
- .module("steamApp")
- .controller("LoginCtrl", function($scope, $window, $rootScope) {
- $scope.test = "hello";
- console.log($scope.test)
- $scope.signin = function (){
- $http.get('http://localhost:4000').success(function(data){
- console.log(data);
- });
- };
- });
- angular.module("steamApp", ["ngRoute"]).config(
- function($routeProvider) {
- $routeProvider
- .when("/", {
- template: "partials/navbar.html",
- controller: "LoginCtrl"
- })
- });
Add Comment
Please, Sign In to add comment