GitHub App's user token can't list private repositories #48102
-
Select Topic AreaQuestion BodyI created a GitHub App (not OAuth App) and tried this API to list all private repositories with the user's token retrieved by OAuth web flow. However, it returned empty. Once I installed the GitHub App to one of my private repositories, the repository was returned but that's all. I couldn't see any other private repositories. Is there any way to list all private repositories which the authenticated user has access? Note: I added "Read-only" permission for content to the GitHub App. Note: I can't see the section like below in the GitHub App's settings.
|
Beta Was this translation helpful? Give feedback.
Replies: 17 comments 14 replies
-
I have the same issue, it's driving me bananas. I have an access token and I'm sending it (the /user/repos endpoint wouldn't work at all if I wasn't). I only get public repos back, no matter what I do. I gave the github app the following permissions, because I also want it to create and manage repositories: Repository Permissions: Administration (read-write), Contents (read-write), Metadata (read-only) Organization Permissions: Members (read-only) What am I missing? |
Beta Was this translation helpful? Give feedback.
-
Did anyone find a solution or the docs that point on how to list a users private repos? |
Beta Was this translation helpful? Give feedback.
-
Using GraphQL works but using api does not work for getting any private repos (org or user) |
Beta Was this translation helpful? Give feedback.
-
Please do lmk if u find a fix for this. :( |
Beta Was this translation helpful? Give feedback.
-
I finally found a solution! 😅 As mentioned here:
I went into my Developer settings, clicked the Github app > Install App |
Beta Was this translation helpful? Give feedback.
-
I still don't have this one resolved either. Glad to see others with the same problem. I have the app installed and have used the APP ID, Installation ID, and certificate to generate authentication with the app. These still only list the public repositories. Even when providing the Any help appreciated. May have to resort to the GraphQL call since that seems to work for folks. |
Beta Was this translation helpful? Give feedback.
-
I have run into this issue at the GitHub app level as well - when using the installation access token and corresponding installation client. |
Beta Was this translation helpful? Give feedback.
-
I am also having the same issue. Not sure whatelse to do. |
Beta Was this translation helpful? Give feedback.
-
🕒 Discussion Activity Reminder 🕒 This Discussion has been labeled as dormant by an automated system for having no activity in the last 60 days. Please consider one the following actions: 1️⃣ Close as Out of Date: If the topic is no longer relevant, close the Discussion as 2️⃣ Provide More Information: Share additional details or context — or let the community know if you've found a solution on your own. 3️⃣ Mark a Reply as Answer: If your question has been answered by a reply, mark the most helpful reply as the solution. Note: This dormant notification will only apply to Discussions with the Thank you for helping bring this Discussion to a resolution! 💬 |
Beta Was this translation helpful? Give feedback.
-
I believe I am experiencing the same. The app is installed to my org with read contents and read metadata on all repositories in the org. I use the private key to generate an installation access token. Both python Github client and curl command using the token show no results for private repos. |
Beta Was this translation helpful? Give feedback.
-
There seems to be a related issue: https://github.com/orgs/community/discussions/113651 |
Beta Was this translation helpful? Give feedback.
-
I had this same issue, realised (as mentioned in the chosen answer) that the app needs to be installed as well as authorised. In my case, to redirect users to an install & authorise page instead of just the authorise page this was as simple as changing the URL that I was redirecting users to to authenticate with my app. Previous URL (only listed public repositories even with repository metadata permission set): https://github.com/login/oauth/authorize?client_id=YOUR_CLIENT_ID&state=STATE Correct URL for app install & authorise: https://github.com/apps/YOUR_APP_NAME/installations/new?client_id=YOUR_CLIENT_ID&scope=repo&state=STATE |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
For anyone still experiencing issues accessing the list of repos, this all boils down to which approach you're taking:
N.B. you can use a combination of the above, but some API endpoints will not accept an installation token. The user token is primarily used so that you can attribute any changes to that user rather than your Github App bot. I hope that helps someone. |
Beta Was this translation helpful? Give feedback.
-
This wasted a good hour for me. I really wonder about their naming choices for the apis/endpoints /**
* Lists repositories that the authenticated user has explicit permission (`:read`, `:write`, or `:admin`) to access.
*
* The authenticated user has explicit permission to access repositories they own, repositories where they are a collaborator, and repositories that they can access through an organization membership.
*/
listForAuthenticatedUser: {
(params?: RestEndpointMethodTypes["repos"]["listForAuthenticatedUser"]["parameters"]): Promise<RestEndpointMethodTypes["repos"]["listForAuthenticatedUser"]["response"]>;
defaults: RequestInterface["defaults"];
endpoint: EndpointInterface<{
url: string;
}>;
};
/**
* Lists repositories for the specified organization.
*
* > [!NOTE]
* > In order to see the `security_and_analysis` block for a repository you must have admin permissions for the repository or be an owner or security manager for the organization that owns the repository. For more information, see "[Managing security managers in your organization](https://docs.github.com/organizations/managing-peoples-access-to-your-organization-with-roles/managing-security-managers-in-your-organization)."
*/
listForOrg: {
(params?: RestEndpointMethodTypes["repos"]["listForOrg"]["parameters"]): Promise<RestEndpointMethodTypes["repos"]["listForOrg"]["response"]>;
defaults: RequestInterface["defaults"];
endpoint: EndpointInterface<{
url: string;
}>;
};
/**
* Lists public repositories for the specified user.
*/
listForUser: {
(params?: RestEndpointMethodTypes["repos"]["listForUser"]["parameters"]): Promise<RestEndpointMethodTypes["repos"]["listForUser"]["response"]>;
defaults: RequestInterface["defaults"];
endpoint: EndpointInterface<{
url: string;
}>;
}; |
Beta Was this translation helpful? Give feedback.
-
From GitHub Support: That is indeed a bug that Engineering has on their backlog to fix. The behavior is documented but you have to switch to the enterprise cloud version of the Docs as below: |
Beta Was this translation helpful? Give feedback.
I finally found a solution! 😅 As mentioned here:
I went into my Developer settings, clicked the Github app > Install App
After installing the app I would finally get the private repos in addition to the public ones in the response from /user/repos