GitHub v3 API: determine if a user owns an organization

It is easy to determine if the User is a member of the team if you know the id :

 GET /teams/:id/members/:user 

But how can you easily identify the identifier of the special Owners team that each Organization has?

As far as I can tell, the only way is to get a complete list of all the teams (which, I believe, can be several pages?), And go through them until you find a name with the name "Owners".

This is doable, of course, but it is uncharacteristically inconvenient for GitHub an otherwise fantastic API .;)

For what it's worth, I tried the following (no luck):

 GET /orgs/:organization/teams?name=Owners # Lists all teams GET /orgs/:organization/owners # 404 

To be clear, I have definitely used a token associated with a user who owns the corresponding organization, so there should not be any problems with authorization.

+7
github-api
source share
3 answers

There is currently no easy way to check if a user is on the owners team. Thanks for the wonderful offer, though !;)

A hacker workaround involves performing a non-destructive operation that is allowed only to the owners. If the operation succeeds, the authenticated user is the owner.

For example, you can try changing your organizationโ€™s settings by sending an empty JSON hash:

 $ curl -v -X PATCH -d '{}' https://api.github.com/orgs/:org?access_token=TOKEN 

If this returns a status code of 200, the user is the owner. The status signal 404 signals otherwise.

We hope that in the future we will be able to offer a more elegant solution.

+5
source share

Alternatively, a faster solution, you can use the memberships API to get detailed information about the authenticated user membership in each organization to which they belong.

The request is just GET /user/memberships/orgs?state=active , and the answer is as follows:

 [ { "state": "active", "role": "admin", "organization": { "login": "octocat", "id": 1, }, "user": { "login": "defunkt", "id": 3, "gravatar_id": "", "type": "User", "site_admin": false } }, { "state": "active", "role": "member", "organization": { "login": "invitocat", "id": 2, }, "user": { "login": "defunkt", "id": 3, "gravatar_id": "", "type": "User", "site_admin": false } } ] 

An important field for designation is the role ; we want only "role": "admin" .

Iโ€™m not sure if this ensures that the user is a member of Owners , but it does indicate that they have the administrative authority of the organization.

+1
source share

Just determine if they are part of a team named โ€œownersโ€ for this organization https://developer.github.com/v3/orgs/teams/#list-team-members

Owners is a special team for GitHub only with owners.

screen shot 2014-10-31 at 9 39 30 am

See https://github.com/orgs/YOURORG/teams/owners

0
source share

All Articles