autohost-github-auth
Advanced tools
Comparing version
@@ -1,5 +0,9 @@ | ||
## 1.0.0-beta | ||
## 1.0.0-beta-1 | ||
- Added option to require organization membership | ||
### 1.0.0-beta | ||
### Initial Release | ||
{ | ||
"name": "autohost-github-auth", | ||
"version": "1.0.0-beta", | ||
"version": "1.0.0-beta-1", | ||
"description": "GitHub auth provider for autohost", | ||
@@ -35,2 +35,3 @@ "main": "src/index.js", | ||
"passport-github2": "^0.1.9", | ||
"request": "^2.67.0", | ||
"when": "~3.1.0" | ||
@@ -37,0 +38,0 @@ }, |
@@ -8,8 +8,10 @@ ## GitHub auth provider for Autohost | ||
"auth": { | ||
"sessionMessages": false, // true to add login failure messages to session | ||
"loginEndpoint": "/auth/login", // this is the public endpoint for your login page | ||
"authEndpoint": "/auth/github", // this is the route that will kickoff the authentication against GitHub | ||
"github": { | ||
"clientId": "YOUR_CLIENT_ID_HERE", | ||
"clientSecret": "YOUR_CLIENT_SECRET_HERE", | ||
"callbackUrl": "http://localhost:3000/auth/github/callback" // this is the route the GitHub will request after authentication | ||
"organization": "ORG-NAME", // optionally add to require org membership | ||
"clientId": "YOUR_CLIENT_ID_HERE", | ||
"clientSecret": "YOUR_CLIENT_SECRET_HERE", | ||
"callbackUrl": "http://localhost:3000/auth/github/callback" // this is the route the GitHub will request after authentication | ||
} | ||
@@ -16,0 +18,0 @@ } |
var _ = require( 'lodash' ); | ||
var when = require( 'when' ); | ||
var request = require( 'request' ); | ||
var GitHubStrategy = require( 'passport-github2' ).Strategy; | ||
@@ -25,2 +26,25 @@ | ||
function validateUserOrg(accessToken, username, done) { | ||
request({ | ||
method: "GET", | ||
url: 'https://api.github.com/orgs/' + config.auth.github.organization + '/members/' + username, | ||
headers: { | ||
"User-Agent": "nodejs", | ||
"Authorization": "token " + accessToken | ||
}, | ||
json: true | ||
}, function(err, res, body) { | ||
if(err) { | ||
return done(err); | ||
} | ||
if(res.statusCode !== 204) { | ||
// This user ain't with us | ||
return done(null, false); | ||
} | ||
done( null, true ); | ||
}); | ||
} | ||
function initGitHubStrategy( config ) { | ||
@@ -37,3 +61,19 @@ var github = new GitHubStrategy( { | ||
// users can or can't do in the app | ||
return done( null, profile ); | ||
if(!config.auth.github.organization) { | ||
return done( null, profile ); | ||
} | ||
validateUserOrg(accessToken, profile.username, function(err, isOrgMember) { | ||
if(err) { | ||
return done(err); | ||
} | ||
if(isOrgMember) { | ||
done(null, profile); | ||
} else { | ||
done(null, false, { message: "User is not a member of the " + config.auth.github.organization + " organization." }); | ||
} | ||
}); | ||
} ); | ||
@@ -53,3 +93,3 @@ } ); | ||
initPassport: function( passport ) { | ||
githubAuth = passport.authenticate( 'github', { scope: ['user:email'], failureRedirect: config.auth.loginEndpoint, session: useSession } ); | ||
githubAuth = passport.authenticate( 'github', { scope: ['user:email', 'read:org'], failureMessage: !!config.auth.sessionMessages, failureRedirect: config.auth.loginEndpoint, session: useSession } ); | ||
}, | ||
@@ -64,2 +104,2 @@ serializeUser: serializeUser, | ||
return wrapper; | ||
} | ||
}; |
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
6264
24.61%95
53.23%20
11.11%4
33.33%2
100%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added