-1

Few days ago i write facebook integration using spring's tutorial. Here is my code

FacebookConnectionFactory connectionFactory = new FacebookConnectionFactory("appId", "appSecret");
    OAuth2Operations oauthOperations = connectionFactory.getOAuthOperations();
    OAuth2Parameters params = new OAuth2Parameters("http://localhost:8080/shop/facebook");
    String authorizeUrl = oauthOperations.buildAuthorizeUrl(GrantType.IMPLICIT_GRANT, params);

    try {
        response.sendRedirect(authorizeUrl);
        LOG.error("ALL WORKING FINE>>>");
    } catch (IOException e) {
        LOG.error("Errorrrrr" + e);
    }
    return null;

Then i should to get access_token, but it comes to me in hash part of the URL(so i should get the access_token using JS) - wrong way. After that i install another tutorial Spring-Social-quickstart and i can not understand how it retrieve access_token? What should i write to get access_token on the server side. Should it be some interceptors of the request, or exists another ways?

Igor Masternoy
  • 436
  • 1
  • 11
  • 36
  • What is not working for you? What errors are you getting? Do you have a problem with the specific code? Show the code. – maksimov Jun 22 '12 at 10:19

1 Answers1

1

The problem was that i expect access_token - but this is client-side authorization. So i should expect authorization code to make a server-side auth.

But now the problem that i caught exception here on accessGrant line. It is an other controller. i get authCode BUT it show me exception 400 : Badrequest.

@RequestMapping(method = RequestMethod.GET) 
public String getAuthorisation(NativeWebRequest webRequest, HttpServletResponse response, HttpServletRequest request) {
    FacebookConnectionFactory connectionFactory = 
            new FacebookConnectionFactory("clientId", "clientSecret");
    OAuth2Operations oauthOperations = connectionFactory.getOAuthOperations();

String authCode = request.getParameter("code");     
    LOG.error("Facebook  controller works... 1");
    LOG.error(authCode);

    AccessGrant accessGrant = oauthOperations.exchangeForAccess(authCode, "http://localhost:8080/shop/pages/social.jsp", null);
    LOG.error("Facebook  controller works... 2");
    Connection<Facebook> connection = connectionFactory.createConnection(accessGrant);
    LOG.error("Facebook  controller works... 3");
    return null;

} 
Igor Masternoy
  • 436
  • 1
  • 11
  • 36