java


Cookie Error while getting OAuth Access Token from GitHub


I am trying to get a GitHub oauth access token. Redirecting the user to
https://github.com/login/oauth/authorize works fine and a get the code.
However, when I do the POST request from the server to https://github.com/login/oauth/acces_token,
the server responds with
403: Forbidden / Cookies must be enabled to use GitHub.
Am I getting something wrong here? It's an API! What is the role of cookies here? How can I fix the error?
My Code is (using 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");
}
Found the error: Typo in the URL. I had acces_token, should be access_token. Now it works like a charm.

Related Links

Android dex issue: nested class + final boolean : com.android.dex.util.ExceptionWithContext
Constructing a Facebook login app for android
Gson Unicode characters not displaying properly in response to front-end
Java error codes
Play Framework 2.1 - requests and loading of static content extremely slow in dev-mode
Thead Dump Java SE scheduled Application stuck issue
hbase delete records based on portion of id
Add listener to JPanel that will be only called onload
Nothing happening? Simple code and new coder? [closed]
Cannot explain behaviour of copyOfRange(int[] a, int from, int to) function
Java error on read text file, “Exception in thread ”main“ java.lang.Error” [duplicate]
StackOverflow error while creating JAXBContext using MOXy in JBoss
Instance Methods: complex numbers
mediaPlayer.setSpu() not working
Declaration of Array not accepted
use java in python 3.4 with nltk

Categories

HOME
date
coq
electron
dxl
alpha
windows-server
ios-charts
google-translate
here-api
spring-kafka
rascal
nstableview
size
hapi
django-simple-history
after-effects
openrefine
code-review
predix
paging
accessor
bootstrap-duallistbox
ping
key-value-observing
jspresso
calibre
framemaker
hybridauth
language-concepts
suricata
lto
neuroscience
reportbuilder
document.write
reportingservices-2005
quadratic-programming
nomethoderror
keydown
acoustics
websphere-mq-fte
jsch
dotcover
pubmed
prolog-setof
nstextview
elgg
drupal-6
windows-mobile-6.5
spring-mongodb
redundancy
migradoc
messenger
visual-c++-2008
angular-cache
skobbler-maps
plottable.js
qpid
multiple-regression
python-stackless
jfugue
google-places
icu4j
python-3.2
tarjans-algorithm
apache-commons-net
website-monitoring
gwidgets
codeigniter-routing
client-side-templating
jquery-layout
marmalade
srs
spring-io
rabl
comaddin
html-editor
enterprisedb
itmstransporter
anonymous-methods
dbproviderfactories
gwt-ext
zpt
xmlspy
radcombobox
blitz++
wise
getresponsestream
vc90
perfect-hash
exchange-server-2003
javap
noscript
nerddinner
post-build

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App