4

I am trying to integrate facebook login with my website. Here is my some part of the code:

public void socialConnect() throws Exception {
    Properties props = System.getProperties();
    props.put("graph.facebook.com.consumer_key", "561379830565954");
    props.put("graph.facebook.com.consumer_secret", "883e8d729d0358b4040fbffa762d832d");
    props.put("graph.facebook.com.custom_permissions", "publish_stream,email,user_birthday,user_location,offline_access");
    SocialAuthConfig config = SocialAuthConfig.getDefault();
    config.load(props);
    manager = new SocialAuthManager();
    manager.setSocialAuthConfig(config);
    ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
    String successURL = externalContext.getRequestContextPath() + "/socialLoginSuccess.xhtml";
    String authenticationURL = manager.getAuthenticationUrl(providerID, successURL);
    FacesContext.getCurrentInstance().getExternalContext().redirect(authenticationURL);
}

I get the following error:

{
  "error": {
    "message": "redirect_uri isn't an absolute URI. Check RFC 3986.",
    "type": "OAuthException",
    "code": 191
  }
}

What should be the redirecct_uri? How can i fix it can anyone help?

Thanks

Ivan Nevostruev
  • 28,143
  • 8
  • 66
  • 82
yrazlik
  • 10,411
  • 33
  • 99
  • 165

1 Answers1

5

Your redirect_uri has to be a fully qualified URL with the protocol (http(s)://), domain, path, etc.

If you're writing a desktop application, according to How to login / authenticate facebook without browser for desktop application in C# there is not explicit support for desktop applications, but there is a workaround (and it's outlined in that question).

Community
  • 1
  • 1
Jim Rubenstein
  • 6,836
  • 4
  • 36
  • 54
  • 1
    I added http:// but still the same error. What should i add more, can you give me an example please? – yrazlik Jul 11 '13 at 21:42
  • If this isn't a web app (which I guess was silly to assume), you'll probably have to follow a different authentication process. editing answer – Jim Rubenstein Jul 11 '13 at 21:46
  • if it is a web app,then what is the actual value of `successURL`? – Jim Rubenstein Jul 11 '13 at 21:50
  • it returns localhost:8080/BankApp/socialLoginSuccess.xhtml where BankApp is the name of my application – yrazlik Jul 11 '13 at 21:53
  • I did like this, String successURL = "http://"+externalContext.getRequestContextPath() + "socialLoginSuccess.xhtml"; is that fine? Still does not work – yrazlik Jul 11 '13 at 21:55
  • Try encoding your `successURL` so it looks like this: `http%3A%2F%2Flocalhost%3A8080%2FBankApp%2FsocialLoginSuccess.xhtml` – Jim Rubenstein Jul 11 '13 at 21:58
  • thanks but i did not understand what you said. What should i do to encode it? – yrazlik Jul 11 '13 at 22:02
  • It's a URL encoded value, it's possible that whatever SDK you're using to create your authentication URL doesn't encode (escape) your success URL, which could be causing the browser to not send the entire URL accurately, which could cause FB to see an invalid URL. Here's a SO question about encoding URIs: http://stackoverflow.com/questions/6198894/java-encode-url – Jim Rubenstein Jul 11 '13 at 22:04
  • 1
    hey i solved the problem it looks like externalContext.getRequestContextPath() already returns a "/" and so i have http:///. Thank you so much – yrazlik Jul 11 '13 at 22:21