Skip to content

Allow limited oauth scopes #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 24, 2015
Merged

Allow limited oauth scopes #45

merged 1 commit into from
Jul 24, 2015

Conversation

samrocketman
Copy link
Member

If using the GitHub OAuth plugin for authentication only, then it doesn't make sense to query GitHub for Organization membership since it will not be using GitHub OAuth for authorization.

This stems from a discussion in pull request #39.

cc @s0undt3ch, @sirosen, @cloudbeesci

@samrocketman samrocketman force-pushed the allow_limited_scopes branch from 1ced0b7 to 67eb146 Compare July 19, 2015 16:58
@samrocketman
Copy link
Member Author

I amended the commit message for grammar.

@jenkinsadmin
Copy link
Member

Thank you for a pull request! Please check this document for how the Jenkins project handles pull requests

@samrocketman
Copy link
Member Author

Peer review is welcome.

@s0undt3ch
Copy link

👍 Thanks!

@samrocketman samrocketman force-pushed the allow_limited_scopes branch from 67eb146 to 9ff2882 Compare July 20, 2015 05:44
GithubSecurityRealm myRealm = (GithubSecurityRealm) Jenkins.getInstance().getSecurityRealm();
String[] myScopes = myRealm.getOauthScopes().split(",");
Arrays.sort(myScopes);
if(Arrays.binarySearch(myScopes, "read:org") >= 0 || Arrays.binarySearch(myScopes, "admin:org") >= 0 || Arrays.binarySearch(myScopes, "user") >= 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This conditional needs a comment.
If I were to come across this line while working on the code, I wouldn't have any idea what's being checked here.
To figure it out, I'd have to reach for the GitHub API docs and work backwards from "What are the common properties of these scopes?"

Probably something like "Check to see if we can read organizational and team memberships" would do the trick

@samrocketman samrocketman force-pushed the allow_limited_scopes branch from 9ff2882 to 65eecb0 Compare July 20, 2015 19:23
@samrocketman
Copy link
Member Author

@sirosen I've updated the pull request to contain an additional scope as well as comments for what it is doing.

@sirosen
Copy link
Contributor

sirosen commented Jul 20, 2015

Awesome, that's exactly what I wanted. 👍
Other than that, this looks good up to my ability to read the code.

@samrocketman
Copy link
Member Author

This should be merged after #47 to make use of the hasScope() function in GithubSecurityRealm.

@samrocketman
Copy link
Member Author

Perhaps make myRealm a private final variable of the GithubAuthenticationToken class. Check for null and set it before using hasScope().

@samrocketman samrocketman force-pushed the allow_limited_scopes branch from 65eecb0 to f51842d Compare July 23, 2015 23:55
If using the GitHub OAuth plugin for authentication only, then it
doesn't make sense to query GitHub for Organization membership since it
will not be using GitHub OAuth for authorization.

This stems from a discussion in pull request #39.
@samrocketman samrocketman force-pushed the allow_limited_scopes branch from f51842d to 6ed061a Compare July 24, 2015 01:36
@samrocketman samrocketman merged commit 6ed061a into master Jul 24, 2015
samrocketman added a commit that referenced this pull request Jul 24, 2015
@samrocketman samrocketman deleted the allow_limited_scopes branch July 24, 2015 01:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants