This repository was archived by the owner on Dec 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Allow limiting authentication to members of a specific GitHub org #14
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4fbfb99
Test limiting authentication to members of a specific GitHub org
edef1c 1e64ae2
Allow limiting authentication to members of a specific GitHub org
edef1c 161da2a
Convert org-membership errors into 401s
edef1c 74e2b28
Take the default GitHub org from the config
edef1c 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 hidden or 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 |
---|---|---|
|
@@ -11,6 +11,7 @@ function AuthenticateGithub(opts) { | |
debug: true, | ||
githubHost: config.githubHost, | ||
githubPathPrefix: '/api/v3', | ||
githubOrg: config.githubOrg, | ||
// label the token that we generate. | ||
note: 'npm on premises solution', | ||
noteUrl: 'https://www.npmjs.org' | ||
|
@@ -82,6 +83,22 @@ AuthenticateGithub.prototype.getAuthorizationToken = function(username, password | |
if (err) reject(err); | ||
else resolve(res.token); | ||
}); | ||
}).then(this.githubOrg && function(token) { | ||
return new Promise(function(resolve, reject) { | ||
github.orgs.getMember({ user: username, org: _this.githubOrg }, function(err, res) { | ||
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. based on this logic, I gather an error is returned if a user is not a member of the organization? You've confirmed this behavior hitting the live API? 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. I have confirmed this behaviour on the live API, yes.
These two unauthenticated:
The GitHub API client you're using handles the redirect — all "not a member" paths return a 404. |
||
if (err) reject(err); | ||
else resolve(token); | ||
}); | ||
}).catch(function(err) { | ||
if (err.code === 404) { | ||
err.code = 401; | ||
err.message = 'unauthorized'; | ||
} else if (err.code === 500) { | ||
err.message = 'GitHub enterprise unavailable'; | ||
} | ||
// this is an error state | ||
throw err; | ||
}); | ||
}); | ||
}; | ||
|
||
|
This file contains hidden or 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.
I know it's been a while, but would it be possible to extend it in order to support multiple organizations? Really don't want to come up with a fork of this repo just because of this restriction.
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.
master...nathan7:multiple-github-orgs this would do the trick — any opinion on this, @bcoe?