java - Facebook OAuth redirect_uri Issue -


i trying build authentication flow in our app facebook in java. using facebook4j library.

my corresponding code follows -

public string authenticate() throws ioexception {     facebook facebook = new facebookfactory().getinstance();     string redirecturl = facebook.getoauthauthorizationurl("http://localhost:9099/default/facebook/verify.html");     servletresponse.sendredirect(redirecturl);     return null; }  public string verify() throws exception {     string code = servletrequest.getparameter("code");     facebook facebook = new facebookfactory().getinstance();     accesstoken accesstoken = facebook.getoauthaccesstoken(code);     string token = accesstoken.gettoken();     servletresponse.getwriter().write(token);     return null; } 

i getting error after redirection on line -

accesstoken accesstoken = facebook.getoauthaccesstoken(code); 

the error follows -

facebookexception{statuscode=400, errortype='oauthexception', errormessage='redirect_uri isn't absolute uri. check rfc 3986.', errorcode=191, errorsubcode=-1, version=2.2.2}     @ facebook4j.internal.http.httpclientimpl.request(httpclientimpl.java:179)     @ facebook4j.internal.http.httpclientwrapper.request(httpclientwrapper.java:65)     @ facebook4j.internal.http.httpclientwrapper.get(httpclientwrapper.java:97)     @ facebook4j.auth.oauthauthorization.getoauthaccesstoken(oauthauthorization.java:107) 

redirecturl getting facebook in first call -

https://www.facebook.com/dialog/oauth?client_id=4161xxxxxx6389&redirect_uri=http%3a%2f%2flocalhost%3a9099%2fdefault%2ffacebook%2fverify.html&scope=email,public_profile,user_friends

tried without using encoding -

https://www.facebook.com/dialog/oauth?client_id=4161xxxxxx6389&redirect_uri=http://localhost:9099/default/facebook/verify.html&scope=email,public_profile,user_friends

it redirecting 'verify' having url -

http://localhost:9099/default/facebook/verify.html?code=aqce4aaipe_c94j3nvnjge_yl_op84vpiguauvfrrxncj_fok8u2kfsxfkgrjwnfl1dqmem8q22m6uavbgstptqoqmjxyildfhkfisfd0ycf_bybe9rnx_yxvfnj3rnlf7bjct4c1uxuuqcxhzjvnn1lbb3lwuhz7enkq0r8k14x7zeviwjbll-vqys1fzucivdbri4stoykzr1rpcsosqq7vdcix3zawnw_nbpzbzu7iuezjibbahyjwkhin47b9aqb3hzxxpe4xxxhxfdsp_h2fhc1yyiojbwgq4qbnwpurp7af-0q_wf71zn4txcqld4#=

facebook4j.properties

oauth.appid=416xxxxxxxxx389 oauth.appsecret=9ed3xxxxxxb6acxxxxxxxxc7acxxxx5 oauth.permissions=email,public_profile,user_friends 

my facebook app basic settings -

enter image description here

the important advanced settings -

enter image description here

i totally aware similar question has been posted earlier multiple times. have gone through every question & tried suggested resolve issue. due reason not working. decided post problem here after spending 3 days on same issue.

i highly appreciate if points out going wrong.

the redirect_uri parameter has specified when exchanging code token (and has same specified earlier in login dialog call).

i’d assume since using new facebookfactory().getinstance() in second method, not case. take @ basic implementation here, https://github.com/roundrop/facebook4j-oauth-example/tree/master/src/main/java/facebook4j/examples/signin

in signinservlet, facebook object instance stored session, , in callbackservlet same instance retrieved , used again. therefor, still holds redirect_uri value used when auth dialog called, , re-use same value when exchanging code token.


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -