Results 1 to 10 of 16

Thread: Facebook connection detection

Hybrid View

  1. #1
    Join Date
    Jul 2012
    Posts
    9

    Default Facebook connection detection

    Assuming a facebook is already establish from the frontend. (Javascript or some other means)

    How can we use use spring social to detect it and add it to the UsersConnectionRepository

    Example:
    userId = Long.toString(userIdSequence.incrementAndGet());
    ConnectionRepository repository = connectionRepository.createConnectionRepository(us erId);

    connectionRepository.createConnectionRepository(us erId).addConnection(connection);

    userCookieGenerator.addCookie(userId, response);
    SecurityContext.setCurrentUser(new User(userId));

    How do we get the facebook connection to be added.

  2. #2
    Join Date
    Aug 2004
    Posts
    1,075

    Default

    There's not (yet) any real integration between Spring Social's server-side Facebook stuff and Facebook's client-side stuff. That is more or less the subject of https://jira.springsource.org/browse/SOCIALFB-40, although the text in that issue speaks more of solving the problem in the other direction. I invite you to share any thoughts/ideas you may have as comments on that issue and vote for it. It's currently not very high on my priority list, but if I get enough feedback and interest I'll be happy to bump it up.
    Craig Walls
    Spring Social Project Lead

  3. #3
    Join Date
    Jul 2012
    Posts
    9

    Default

    Sorry i am new to all this.

    What i am looking at is only manually adding of the facebook connection like a provider into UsersConnectionRepository.

    I can't use MVC view to "control" the connection to "signin/facebook"

    the solution provided seems to be the other way round.

  4. #4
    Join Date
    Aug 2004
    Posts
    1,075

    Default

    Right...and that's what I said in my earlier response: "...the text in that issue speaks of solving the problem in the other direction." Truly that issue should reflect a more general (either direction) approach for integrating the client-side stuff with the server-side stuff.

    That said, it's not impossible to solve the problem with Spring Social as-is: There's no reason why you can't create a controller that is injected with the ConnectionRepository and uses it to save a connection...a connection that is created from the token given to it from the client-side. You can create the connection by calling createConnection() on the FacebookConnectionFactory, passing in an AccessGrant instance.

    It's a lot more manual work on your part (which is why it'd be nice for Spring Social to directly support it), but it can be done.
    Craig Walls
    Spring Social Project Lead

  5. #5
    Join Date
    Jul 2012
    Posts
    9

    Default

    Tried to change the code to something like this but got an MissingAuthorizationException
    Code:
    AccessGrant accessGrant = new AccessGrant(accessToken);
    OAuth2ConnectionFactory<?> connectionFactory = (OAuth2ConnectionFactory<?>) connectionFactoryLocator.getConnectionFactory(Facebook.class);
    Connection<?> connection = connectionFactory.createConnection(accessGrant);

  6. #6
    Join Date
    Oct 2011
    Location
    London, UK
    Posts
    27

    Default

    Hi

    The code you posted does work if you pass in a valid accessToken and if you have registered a Facebook connection factory with the locator with a valid clientId and secret. I just ran this locally and I did get a MissingAuthorizationException if the accessToken is blank, but with a valid access token this gave me a connection I could use to retrieve user profile data from Facebook.

    Can I ask how you are getting the value of the access token you are passing in?

    Facebook provides a "code" parameter in its callback from the permissions dialog that the user approves when they give access to your application. The "accessToken" in the your code must be the access grant that is given by Facebook in exchange for this code - not the code itself. If you do have access to the "code" parameter given in the callback from the permissions dialog, instead of using the AccessGrant constructor in your code above, you can retrieve the access grant as follows:

    AccessGrant accessGrant = connectionFactory.getOAuthOperations().exchangeFor Access(code, redirectUrl, null);

    where redirectUrl is your application url that Facebook redirected to when it passed back the "code" parameter.

    Hope this helps

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •