Created
June 12, 2015 16:19
-
-
Save DavidSouther/3813d37375bd072f8bae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var config = { | |
name: 'rupert-auth-example', | |
hostname: 'localhost', | |
stassets: { | |
root: './src/client' | |
}, | |
server: { | |
root: './src/server' | |
}, | |
mongo: { | |
rest: false | |
}, | |
doorman: { | |
providers: { | |
google: { | |
// Get these from https://console.developers.google.com | |
clientID: "your_client_id.apps.googleusercontent.com", | |
clientSecret: process.env['GOOGLE_SECRET'], | |
scope: ['profile'] | |
} | |
} | |
} | |
}; | |
require('rupert')(config).start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html5> | |
<html lang="en"> | |
<head> | |
<title>Authentication Demo</title> | |
<link rel="stylesheet" href="/vendors.css"/> | |
</head> | |
<body> | |
<div class="container"> | |
<h1 class="title">Rupert Auth Demo</h1> | |
<div> | |
<a href="#" id="login" class="btn btn-primary">Login with Google</a> | |
<p id="hello" class="bg-info"></p> | |
<h2>I have greeted</h2> | |
<ul id="greeted"></ul> | |
</div> | |
</div> | |
<script src="/vendors.js"></script> | |
<script src="/application.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.get('/greet').then(addNames); | |
window.RupertDoormanLoggedIn = function(){ | |
$.get('/doorman').then(function(user){ | |
$('#hello').text(user.displayName); | |
addNames([user.displayName]); | |
}); | |
} | |
$('#login').on('click', function(){ | |
window.open('/doorman/google/connect'); | |
}); | |
function addNames(names){ | |
names.forEach(function(name){ | |
$('#greeted').append($('<li>').text(name)); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"dependencies": { | |
"passport-google-oauth": "^0.2.0", | |
"rupert": "^0.3.8", | |
"rupert-doorman": "0.0.7", | |
"rupert-plugin-bootstrap": "^0.1.1", | |
"rupert-plugin-mongo": "0.0.6" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var greeted = []; | |
var mongo = require('rupert-plugin-mongo'); | |
var doorman = require('rupert-doorman'); | |
doorman.storage.Store = function(provider, user) { | |
return mongo.getDatabase().then(function(db){ | |
return new Promise(function(resolve, reject){ | |
db.collection('users', function(err, collection){ | |
if(err){ return reject(err); } | |
collection.insert({name: user.displayName}, function(err){ | |
if(err){ return reject(err); } | |
resolve(user); | |
}); | |
}); | |
}); | |
}); | |
} | |
module.exports = function (app, config) { | |
app.get('/greet', function(request, response, next){ | |
app.mongo.db.collection('users', function(err, collection){ | |
if(err){ return next(err); } | |
collection.find({}, {}, function(err, cursor){ | |
if(err){ return next(err); } | |
cursor.toArray(function(err, docs){ | |
if(err){ return next(err); } | |
return response.status(200).send(docs.map(function(doc){ | |
return doc.name; | |
})); | |
}); | |
}); | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment