diff --git a/examples/login/app.js b/examples/login/app.js deleted file mode 100644 index 7d7e75e..0000000 --- a/examples/login/app.js +++ /dev/null @@ -1,122 +0,0 @@ -var express = require('express') - , passport = require('passport') - , util = require('util') - , GitHubStrategy = require('passport-github').Strategy; - -var GITHUB_CLIENT_ID = "--insert-github-client-id-here--" -var GITHUB_CLIENT_SECRET = "--insert-github-client-secret-here--"; - - -// Passport session setup. -// To support persistent login sessions, Passport needs to be able to -// serialize users into and deserialize users out of the session. Typically, -// this will be as simple as storing the user ID when serializing, and finding -// the user by ID when deserializing. However, since this example does not -// have a database of user records, the complete GitHub profile is serialized -// and deserialized. -passport.serializeUser(function(user, done) { - done(null, user); -}); - -passport.deserializeUser(function(obj, done) { - done(null, obj); -}); - - -// Use the GitHubStrategy within Passport. -// Strategies in Passport require a `verify` function, which accept -// credentials (in this case, an accessToken, refreshToken, and GitHub -// profile), and invoke a callback with a user object. -passport.use(new GitHubStrategy({ - clientID: GITHUB_CLIENT_ID, - clientSecret: GITHUB_CLIENT_SECRET, - callbackURL: "http://127.0.0.1:3000/auth/github/callback" - }, - function(accessToken, refreshToken, profile, done) { - // asynchronous verification, for effect... - process.nextTick(function () { - - // To keep the example simple, the user's GitHub profile is returned to - // represent the logged-in user. In a typical application, you would want - // to associate the GitHub account with a user record in your database, - // and return that user instead. - return done(null, profile); - }); - } -)); - - - - -var app = express.createServer(); - -// configure Express -app.configure(function() { - app.set('views', __dirname + '/views'); - app.set('view engine', 'ejs'); - app.use(express.logger()); - app.use(express.cookieParser()); - app.use(express.bodyParser()); - app.use(express.methodOverride()); - app.use(express.session({ secret: 'keyboard cat' })); - // Initialize Passport! Also use passport.session() middleware, to support - // persistent login sessions (recommended). - app.use(passport.initialize()); - app.use(passport.session()); - app.use(app.router); - app.use(express.static(__dirname + '/public')); -}); - - -app.get('/', function(req, res){ - res.render('index', { user: req.user }); -}); - -app.get('/account', ensureAuthenticated, function(req, res){ - res.render('account', { user: req.user }); -}); - -app.get('/login', function(req, res){ - res.render('login', { user: req.user }); -}); - -// GET /auth/github -// Use passport.authenticate() as route middleware to authenticate the -// request. The first step in GitHub authentication will involve redirecting -// the user to github.com. After authorization, GitHubwill redirect the user -// back to this application at /auth/github/callback -app.get('/auth/github', - passport.authenticate('github'), - function(req, res){ - // The request will be redirected to GitHub for authentication, so this - // function will not be called. - }); - -// GET /auth/github/callback -// Use passport.authenticate() as route middleware to authenticate the -// request. If authentication fails, the user will be redirected back to the -// login page. Otherwise, the primary route function function will be called, -// which, in this example, will redirect the user to the home page. -app.get('/auth/github/callback', - passport.authenticate('github', { failureRedirect: '/login' }), - function(req, res) { - res.redirect('/'); - }); - -app.get('/logout', function(req, res){ - req.logout(); - res.redirect('/'); -}); - -app.listen(3000); - - -// Simple route middleware to ensure user is authenticated. -// Use this route middleware on any resource that needs to be protected. If -// the request is authenticated (typically via a persistent login session), -// the request will proceed. Otherwise, the user will be redirected to the -// login page. -function ensureAuthenticated(req, res, next) { - if (req.isAuthenticated()) { return next(); } - res.redirect('/login') -} diff --git a/examples/login/package.json b/examples/login/package.json deleted file mode 100644 index b496f25..0000000 --- a/examples/login/package.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "passport-github-examples-login", - "version": "0.0.0", - "dependencies": { - "express": "3.x.x", - "ejs": ">= 0.0.0", - "passport": ">= 0.0.0", - "passport-github": ">= 0.0.0" - } -} diff --git a/examples/login/views/account.ejs b/examples/login/views/account.ejs deleted file mode 100644 index c4633d6..0000000 --- a/examples/login/views/account.ejs +++ /dev/null @@ -1,4 +0,0 @@ -

ID: <%= user.id %>

-

Username: <%= user.username %>

-

Name: <%= user.displayName %>

-

Email: <%= user.emails[0].value %>

diff --git a/examples/login/views/index.ejs b/examples/login/views/index.ejs deleted file mode 100644 index 15db9c0..0000000 --- a/examples/login/views/index.ejs +++ /dev/null @@ -1,5 +0,0 @@ -<% if (!user) { %> -

Welcome! Please log in.

-<% } else { %> -

Hello, <%= user.displayName %>.

-<% } %> diff --git a/examples/login/views/layout.ejs b/examples/login/views/layout.ejs deleted file mode 100644 index b2ef4fa..0000000 --- a/examples/login/views/layout.ejs +++ /dev/null @@ -1,21 +0,0 @@ - - - - Passport-GitHub Example - - - <% if (!user) { %> -

- Home | - Log In -

- <% } else { %> -

- Home | - Account | - Log Out -

- <% } %> - <%- body %> - - diff --git a/examples/login/views/login.ejs b/examples/login/views/login.ejs deleted file mode 100644 index d2dc1bb..0000000 --- a/examples/login/views/login.ejs +++ /dev/null @@ -1 +0,0 @@ -Login with GitHub