403在github上使用组织api时禁止使用

时间:2017-08-15 11:13:55

标签: github oauth github-api

使用github api将用户添加到组织时遇到了一些问题。 我使用GET request来获取我所有者所在组织的会员资格。但我得到了答复

GET http://api.github.com/orgs/romanc-org/memberships/gromanc
Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

 -- response --
403 Forbidden
Server:  GitHub.com
Date:  Tue, 15 Aug 2017 10:34:33 GMT
Content-Type:  application/json; charset=utf-8
Transfer-Encoding:  chunked
Status:  403 Forbidden
X-RateLimit-Limit:  5000
X-RateLimit-Remaining:  4995
X-RateLimit-Reset:  1502793489
X-OAuth-Scopes:  admin:org, repo, user
X-Accepted-OAuth-Scopes:  admin:org, read:org, repo, user, write:org
X-OAuth-Client-Id:  212a8581bdca54d1f503
X-GitHub-Media-Type:  github.v3; format=json
access-control-expose-headers:  ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval
Access-Control-Allow-Origin:  *
content-security-policy:  default-src 'none'
Strict-Transport-Security:  max-age=31536000; includeSubdomains; preload
X-Content-Type-Options:  nosniff
X-Frame-Options:  deny
X-XSS-Protection:  1; mode=block
X-Runtime-rack:  0.027377
Content-Encoding:  gzip
X-GitHub-Request-Id:  2F55:2B87:2E85F4A:6FC7673:5992CE39

{
  "message": "You must be a member of romanc-org to see membership information for gromanc.",
  "documentation_url": "https://developer.github.com/v3/orgs/members/#get-organization-membership"
}

我尝试获取其他用户状态,但错误地使用相同的错误。

我也试过PUT a user to the organization但是

PUT http://api.github.com/orgs/romanc-org/memberships/bt080527
Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Content-Type: application/json
{
  "login": "bt080527",
  "id": 30951532,
  "avatar_url": "https://avatars2.githubusercontent.com/u/30951532?v=4",
  "gravatar_id": "",
  "url": "https://api.github.com/users/bt080527",
  "html_url": "https://github.com/bt080527",
  "followers_url": "https://api.github.com/users/bt080527/followers",
  "following_url": "https://api.github.com/users/bt080527/following{/other_user}",
  "gists_url": "https://api.github.com/users/bt080527/gists{/gist_id}",
  "starred_url": "https://api.github.com/users/bt080527/starred{/owner}{/repo}",
  "subscriptions_url": "https://api.github.com/users/bt080527/subscriptions",
  "organizations_url": "https://api.github.com/users/bt080527/orgs",
  "repos_url": "https://api.github.com/users/bt080527/repos",
  "events_url": "https://api.github.com/users/bt080527/events{/privacy}",
  "received_events_url": "https://api.github.com/users/bt080527/received_events",
  "type": "User",
  "site_admin": false,
  "name": null,
  "company": null,
  "blog": "",
  "location": null,
  "email": null,
  "hireable": null,
  "bio": null,
  "public_repos": 0,
  "public_gists": 0,
  "followers": 0,
  "following": 0,
  "created_at": "2017-08-12T09:57:40Z",
  "updated_at": "2017-08-12T09:57:40Z"
}

 -- response --
403 Forbidden
Server:  GitHub.com
Date:  Tue, 15 Aug 2017 10:47:51 GMT
Content-Type:  application/json; charset=utf-8
Transfer-Encoding:  chunked
Status:  403 Forbidden
X-RateLimit-Limit:  5000
X-RateLimit-Remaining:  4997
X-RateLimit-Reset:  1502797454
X-OAuth-Scopes:  admin:org, repo, user
X-Accepted-OAuth-Scopes:  admin:org, repo
X-OAuth-Client-Id:  212a8581bdca54d1f503
X-GitHub-Media-Type:  github.v3; format=json
access-control-expose-headers:  ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval
Access-Control-Allow-Origin:  *
content-security-policy:  default-src 'none'
Strict-Transport-Security:  max-age=31536000; includeSubdomains; preload
X-Content-Type-Options:  nosniff
X-Frame-Options:  deny
X-XSS-Protection:  1; mode=block
X-Runtime-rack:  0.200124
Content-Encoding:  gzip
X-GitHub-Request-Id:  2FED:2B88:139A091:2BBE319:5992D157

{
  "message": "You must be an admin to add or update an organization membership.",
  "documentation_url": "https://developer.github.com/v3/orgs/members/#add-or-update-organization-membership"
}

我做错了什么?

1 个答案:

答案 0 :(得分:1)

之所以发生这种情况,是因为您正在使用OAuth应用程序的令牌来对组织执行操作。该组织已启用此功能:

https://help.github.com/articles/about-oauth-app-access-restrictions/

但有问题的申请尚未列入白名单。因此,该功能启动并使API表现为您不是组织的成员。

您需要将有问题的应用程序列入白名单,或者禁用该功能。