0
GitHub oauthアクセストークンを取得しようとしています。ユーザーを https://github.com/login/oauth/authorizeにリダイレクトすると問題なく動作し、コードを取得できます。私は 、https://github.com/login/oauth/acces_tokenにサーバーからのPOSTリクエストを行う際にGitHubからOAuthアクセストークンを取得中のCookieエラー
ただし、サーバーは、私がここで間違って何かを取得しています
403: Forbidden/Cookies must be enabled to use GitHub.
で応答しますか?それはAPIです!ここでクッキーの役割は何ですか?エラーを修正するにはどうすればよいですか?
私のコードです(OkHttpを使用して)
String code= ...;
HttpUrl url = new HttpUrl.Builder()
.scheme("https").host("github.com")
.addPathSegments("login/oauth/acces_token")
.build();
StringBuilder formEncoded = new StringBuilder();
formEncoded.append("client_id=").append(URLEncoder.encode(..., "UTF-8"));
formEncoded.append("&client_secret=").append(URLEncoder.encode(..., "UTF-8"));
formEncoded.append("&code=").append(URLEncoder.encode(code, "UTF-8"));
Response resp = client.newCall(
new Request.Builder().url(url)
.post(RequestBody.create(
MediaType.parse("application/x-www-form-urlencoded"),
formEncoded.toString()))
.addHeader("Accept", "application/json").build())
.execute();
if (resp.code() != HttpServletResponse.SC_OK) {
log.error("Error while getting token: {}: {}/{}",
resp.code(), resp.message(), resp.body().string());
throw new RuntimeException("Error while getting access token");
}
http://fajitanachos.com/Authenticating-with-the-GitHub-API/とhttps://github.com/vjeux/GithubLogin/blob/master/token.phpも参照してください。 – ruediste