Fine‑grained PATs cannot be used to verify whether a user is an organization owner (admin) — API returns empty admin list unless using classic PAT with read:org
#189593
Replies: 3 comments
-
|
A solution would be to leave the check out of it, the check which verifies if it's an owner/admin has the correct rights etc, and use a trail and error approach, however applieing this to the creation of many repoes would create a lot of "failure" spam. Thus this creates a desire to have an API to prevent this trail and error approach to not waste bandwidth and not do a trail and error approach... also to prevent halfly or wrongly constructed repos where some actions succeed and some fail becomes of not enough rights etc... Intended use case for tool is creating many git submodules for dependencies which will be forked to allow code changes to the dependencies. All AIs agree, one AI wanted me to mention this, maybe it helps you understand the problem a bit better: "This creates a security paradox: to perform a simple check if a user is an admin, developers are forced to use a Classic PAT with broad read:org scopes, which grants more access than desired, simply because Fine-grained PATs lack the granular 'Organization Members' read permission." |
Beta Was this translation helpful? Give feedback.
-
|
I tried this approach and it also did not work: When using a fine‑grained GitHub Personal Access Token (PAT), every attempt to create a repository inside a GitHub organization fails with HTTP 403 Forbidden. This happens even when the token has all available repository‑related permissions enabled. The reason is that fine‑grained PATs do not support organization‑level repository creation rights. GitHub does not allow fine‑grained tokens to create new repositories in organizations, regardless of the permissions selected. As a result, the tool correctly attempts to create each repository, but GitHub consistently returns: This behavior is expected and cannot be resolved in the tool itself. To successfully create repositories in an organization, a classic PAT with the |
Beta Was this translation helpful? Give feedback.
-
GitHub Feedback: Fine-grained PAT org permissions GitHub Apps can request members: read organization permission Ask the user to confirm they are an org owner during setup |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Problem Summary
I am building a tool that needs to determine whether the authenticated user (via PAT) is an owner/admin of a GitHub organization. This is required before allowing automated repository creation and other org‑level operations.
The problem is that fine‑grained personal access tokens cannot be used for this, because the GitHub API does not return organization admin/member information unless a classic PAT with
read:orgis used.This makes it impossible to reliably detect organization ownership using fine‑grained tokens.
Technical Details
1. API calls used
My tool uses the documented endpoints:
GET /user→ to identify the authenticated user
GET /users/{org}→ to detect whether the target is a user or an organization
GET /orgs/{org}/members?role=admin→ to check if the authenticated user is an organization owner
GET /orgs/{org}/memberships/{username}→ fallback membership check
2. Behavior with classic PAT (works correctly)
When using a classic PAT with scopes:
reporead:orgthe API behaves as expected:
/members?role=adminreturns the full list of organization admins3. Behavior with fine‑grained PAT (broken / incomplete)
When using a fine‑grained PAT, even with:
the following happens:
/orgs/{org}/members?role=adminreturns HTTP 200 but an empty array/orgs/{org}/memberships/{username}returns 403 Forbidden4. Root cause
Fine‑grained PATs cannot request or receive organization‑level permissions such as:
Even if the token has full repository access, the organization permissions section always shows:
This makes it impossible to use fine‑grained tokens for any workflow that requires org‑level identity or ownership checks.
Why this is a problem
GitHub is encouraging users to migrate from classic PATs to fine‑grained PATs, but:
This leaves developers in a situation where:
What I am asking GitHub
read:org‑equivalent permissions?Conclusion
Right now, fine‑grained PATs cannot replace classic PATs for any tool that needs to:
This seems like a significant gap in the fine‑grained token model, and I would appreciate clarification or guidance on how to handle this use case going forward.
Beta Was this translation helpful? Give feedback.
All reactions