Getting Private Repos From Organization with GitHub API V3 Getting Private Repos From Organization with GitHub API V3 git git

Getting Private Repos From Organization with GitHub API V3


I have found the problem and corrected it. According the the GitHub API V3 there are multiple scopes that can be used. It seems the the "user" scope is not valid anymore. Once I used just the "repo" scope everything was retrieved correctly (private org repos, and private forked org repos).


I could not find a correct answer for this at the time, and I don't want to ask for the scope "repo" since it's too overkill for my application, it asks for code read/write permssions. Here's what worked for me (I'm using Ruby along with the octokit gem (https://github.com/octokit/octokit.rb)), special thanks to Ivan from the github dev support:

1.- During Oauth, ask for the "read:org" scope and get the Oauth 2 token from Github

2.- initialize octokit's client:

client = Octokit::Client.new(access_token: my_oauth2_token)

3.- Retrieve the user's organizations, we can do it because of the "read:org" scope

organizations = client.organizations

4.- For each organization, retrieve a Github admin Team to which this user belongs. And then, use this Team to retrieve the repos available

organizations.each do |organization|    admin_team = client.organization_teams(organization[:id]).select { |repo| repo[:permission] == 'admin' }.first    org_repos << client.team_repositories(admin_team[:id])end

Yes, you will definitely need more requests to gather all the available repos, but as I said before, In my case, I did not want to ask for the "user" scope.

Note: Yes, the user have to be a member of an "admin" Team within a given Organization to be able to see the private repos.