所以如果你想通过GitHub的API来做到这一点,你的请求需要改变。
首先,你需要使用的/authorizations
endpoint像这样:
POST /authorizations
Authorization: Basic ...
Content-Type: application/json
Content-Length: ...
{
"scopes": [
"repo",
"write:org"
],
"note": "Example from StackOverflow by @sigmavirus24",
"client_id": "Your client_id here",
"client_secret": "Your client_secret here",
"fingerprint": "1234",
}
这应该然后用身体返回201 Created
响应,像这样:
{
"id": 72249124,
"url": "https://api.github.com/authorizations/72249124",
"scopes": [
"repo",
"write:org"
],
"token": "abcdefgh12345678",
"token_last_eight": "12345678",
"hashed_token": "25f94a2a5c7fbaf499c665bc73d67c1c87e496da8985131633ee0a95819db2e8",
"app": {
"url": "http://my-github-app.com",
"name": "my github app",
"client_id": "abcde12345fghij67890"
},
"note": "optional note",
"note_url": "http://optional/note/url",
"updated_at": "2017-02-08T20:39:23Z",
"created_at": "2017-02-08T17:26:27Z",
"fingerprint": "1234"
}
除了这将是真实的。
也就是说,您似乎在尝试使用允许GitHub用作身份验证提供程序的端点。换句话说,您正在构建一个允许用户使用GitHub登录的应用程序。如果是这种情况,那么你需要特别关注Web Application Flow for OAuth。
在那种情况下,你是那里的一部分,但是你发送的参数是错误的。
首先你做一个GET请求:
GET https://github.com/login/oauth/authorize?client_id=<your-client_id>&scopes=repo%20write:org&state=something-random
然后您将收到的数据从GitHub回来,您必须在您的文章使用
POST https://github.com/login/oauth/access_token?client_id=<your-client_id>&client_secret=<your-client_secret>&code=<code-from-github>
Accept: application/json
之后,你做的任何要求必须有
Authorization: token <token-received-in-response-to-POST>
干杯!
你的问题非常模糊。我在回答中发布了两种可能的解决方案。如果他们不正确,你会*需要更新你的问题,因为细节太少。 –
罗姆人,你能看看我的答案,并让我知道你是否还有其他问题? –