This repository has been archived by the owner on Jun 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
1 integrate passport GitHub auth #114
Merged
Merged
Changes from 11 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f1ac2b4
adding passport libs.
elixic a39d47b
adding the auth routes to the main app and a mixin for the sub apps.
elixic b691e94
a few issues with file names and left session out of packager.json ac…
elixic 0507815
renamed authenticator to passport and modified main to use require th…
elixic e897918
changing response for bad authentication to be a 401 and fixing a req…
elixic 6f19f21
adding login page and making sure redirects and config values are pro…
elixic d653ac9
adding membershipt check
elixic 27b0091
fix a few typos and took out some logging the authentication now ensu…
elixic 06ef2b4
Merging in changes from master so the auth can be integrated with the…
elixic ed2c00b
merging master
elixic d4d5c1e
removing some debug logging.
elixic b6f8bac
removing unused dependency method-override.
elixic 3b7eb23
addressing some concerns in the pull request comment and adding mock …
elixic 2523cb6
merging master.
elixic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<a href="/auth/github">Login with GitHub</a> |
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ module.exports = { | |
config: { | ||
org: org | ||
}, | ||
isMember: Bluebird.promisify(github.orgs.getMember), | ||
getUsers: Bluebird.promisify(github.orgs.getMembers), | ||
getUser: Bluebird.promisify(github.user.getFrom), | ||
getRepos: Bluebird.promisify(github.repos.getFromOrg), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The aliases of these are a little inconsistent? Member vs user |
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,15 +2,43 @@ | |
|
||
exports.start = () => { | ||
|
||
var express = require('express'), | ||
// HACKING IN CONFIG OBJECT HERE | ||
var config = { | ||
server: { | ||
port: '3000', | ||
api_prefix: '/api/v1', | ||
hostname: 'localhost' | ||
}, | ||
github: { | ||
clientID: process.env.GITHUB_CLIENTID, | ||
clientSecret: process.env.GITHUB_CLIENT_KEY, | ||
authRoute: '/auth/github', | ||
authCallbackRoute: '/auth/github/callback', | ||
failureCallback: '/auth/failure' | ||
}, | ||
session: { | ||
secret: 'keyboard cat', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this useful for anyone forking the app, or should it be pulled out as an env variable? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should maybe do something like |
||
resave: false, | ||
saveUninitialized: true, | ||
cookie: { | ||
secure: false | ||
} | ||
}}, | ||
express = require('express'), | ||
mountie = require('express-mountie'), | ||
http = require('http'), | ||
path = require('path'), | ||
session = require('express-session'), | ||
passport = require('./passport'), | ||
app = express(); | ||
|
||
app.set('port', 3000); | ||
app.use(session(config.session)); | ||
|
||
passport.setup(app, config); | ||
|
||
app.set('port', config.server.port); | ||
app.use(express.static(path.resolve(__dirname, '../../app/client/build'))); | ||
|
||
mountie({ | ||
parent: app, | ||
src: path.join(__dirname, 'apps'), | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
|
||
var users = require('../components/repositories/users'); | ||
|
||
module.exports = { | ||
isAuthenticated (req, res, next) { | ||
var authenticated = req.isAuthenticated(); | ||
|
||
if (authenticated && users.isMember(req.session.passport.user.username)) { | ||
next(); | ||
} else { | ||
res.send(401); | ||
} | ||
} | ||
}; |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
'use strict'; | ||
|
||
|
||
var passport = require('passport'), | ||
GitHubStrategy = require('passport-github').Strategy, | ||
debug = require('debug')('app:passport'); | ||
|
||
module.exports = { | ||
/** | ||
* Sets up passport-github for authentication by creating routes on the app for retrieving oauth tokens from | ||
* github. | ||
* | ||
* @param app the app that will use the githug authentication | ||
* @param config configuration from the app using the authenticator | ||
*/ | ||
setup: function (app, config) { | ||
passport.use(new GitHubStrategy({ | ||
clientID: config.github.clientID, | ||
clientSecret: config.github.clientSecret, | ||
callbackURL: "http://" + config.server.hostname + ":" + config.server.port + config.github.authCallbackRoute | ||
}, | ||
function (accessToken, refreshToken, profile, done) { | ||
done(null, { username: profile.username, displayName: profile.displayName, id: profile.id, token: accessToken }); | ||
})); | ||
|
||
passport.serializeUser(function (user, done) { | ||
debug("serialize user"); | ||
debug(user); | ||
done(null, user); | ||
}); | ||
|
||
passport.deserializeUser(function (user, done) { | ||
debug("deserialize user"); | ||
debug(user); | ||
done(null, user); | ||
}); | ||
|
||
app.use(passport.initialize()); | ||
app.use(passport.session()); | ||
|
||
|
||
app.get('/auth/authenticated', function (req, res) { | ||
var authenticated = req.isAuthenicated(); | ||
if (authenticated) { | ||
res.send(200); | ||
} else { | ||
res.send(401); | ||
} | ||
}); | ||
app.get(config.github.authRoute, passport.authenticate('github')); | ||
app.get(config.github.authCallbackRoute, passport.authenticate('github', | ||
{ failureRedirect: config.github.failureRedirect, session: true }), | ||
function (req, res) { | ||
var authenticated = req.isAuthenticated(); | ||
debug("authenticated? " + authenticated); | ||
// TODO: redirect to initial request location... | ||
res.redirect('/'); | ||
} | ||
); | ||
app.get(config.github.failureCallback, function (req, res, next) { | ||
res.send(401); | ||
}); | ||
} | ||
}; |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't need the $rootScope dep