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

How to change background color at JFrame
Need to resize my JTextArea where some content is already present
Hibernate does suboptimally queries
Pause Button in Java Game
Reading from a file, running out of memory
How to I validated an input for being an Int and within a number range?
Program hangs on executeBatch()
Filtering XML Document using XPATH in java
Unable to import gpdraw in Java
Setting Android Manifest Tags Dynamically
Spring Security authentication from custom tables
Jackson API to store datetime
How to represent a response body in xml
JPA 2 Hibernate Group BY and Count * with other columns
HibernateSystemException: could not deserialize
Java8 LocalDateTime parsing error

Categories

HOME
google-play
tinymce
plone
fme
alfresco
leon
rdf
cakephp-2.5
sql-server-2016
callback
basic
tomcat6
node-pdfkit
izpack
qt-creator
vb.net-2010
static-libraries
django-simple-history
pc
transformation
interop
jqwidget
code-review
functional-testing
tapestry
pass-by-reference
wijmo
crosstab
p-value
minitab
elasticsearch-net
tasklet
newline
bluestacks
fabric8
stormpath
column-family
grails-3.1
perlin-noise
force-layout
web-mining
vapor
temporary-files
elasticsearch-plugin
sfdc
node-gyp
atomicity
worksheet
git-diff
lowpass-filter
libusb-win32
google-perftools
knpmenubundle
pdfclown
spring-mongodb
vtigercrm
objective-c-swift-bridge
ableton-live
infix-notation
mikroc
login-control
fputcsv
react-native-listview
prettytensor
hover-over
phpcas
srand
r-tree
marching-cubes
qdialog
sframe
processmodel
directoryservices
npapi
nsbutton
applescript-objc
markers
php-5.4
elliptic-curve
yorick
valuechangelistener
transcoding
message-driven-bean
algebraic-data-types
uv-mapping
gnu-smalltalk
runtime.exec
ftps
padarn
hosts-file
wse3.0
postgresql-performance
gnustep
pydot
genshi
coredump
nsviewanimation
web-architecture
boost-smart-ptr
nerddinner
sector
msdev
paul-graham

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