2017-08-15 57 views
1

我在使用github api向組織添加用戶時遇到了一些問題。 我已使用GET request獲得我是所有者的組織的成員身份。但我得到的迴應403在github上使用組織API時禁止

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" 
} 

我試圖獲取其他用戶的狀態,但faile與相同的錯誤。

我也試圖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

發生這種情況的原因是您使用OAuth應用程序的標記對組織執行操作。該組織已啓用此功能:

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

,但有問題的應用尚未被列入白名單。所以,該功能會啓動並使API的行爲與您不是該組織的成員一樣。

您需要將該組織的應用列入白名單,或者禁用該功能。

+0

謝謝,我沒有在開發者網站上找到這個鏈接。現在它在嚮應用程序提供權限後正在工作。 –