Announcement Announcement Module
Collapse
No announcement yet.
[Spring Social] : UserConnections Table Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • [Spring Social] : UserConnections Table

    Hello,
    I have a misunderstanding regarding storing users connections, and also checking users existence in db, please help.

    My problems:
    1. I don't have any data in my UserConnections table, after i've done a facebook connection for example.
    Should I manage it by my self?

    2. I have a database with Account table and UserConnections table. As I saw in JdbcUsersConnectionRepository.findUserIdsConnected To() method, the selector looks for the data only in UserConnections table and if there are no data associated for userId, it redirects me to signup page.
    Should I create a custom JdbcUsersConnectionRepository and to rewrite findUserIdsConnectedTo method in order to check for existing users in Account table also?

    Thanks a lot in advance for any help.

  • #2
    1. Your project code correctly integrated with Spring Social should put FB data there by calling SS functionality. It's like 'semi-automatic' functionality.

    2.
    JdbcUsersConnectionRepository.findUserIdsConnected To() method, the selector looks for the data only in UserConnections table and if there are no data associated for userId, it redirects me to signup page.
    It's correct, it wants FB data to be stored in UserConnection. As you don't have #1 working correctly, it goes to SignUp.

    3.
    Should I create a custom JdbcUsersConnectionRepository and to rewrite findUserIdsConnectedTo method in order to check for existing users in Account table also?
    Usually you don't have to do.
    Rather you should add your custom code + UI for, say, completing User registration inside your system. Say, User can land to additional page and adjust/confirm some data received by you from FB. After that you should store user's Account data in your system using FB info and you can 'reference/connect' your Account record with UserConnection record by using Account's foreign key to UC id.... or something similar.... The details are up to you.

    Comment


    • #3
      Hi blandger, thanks for your message.
      Can you explain a bit more about SS insertion flow, when it exactly start, or what's the service class name? That will help me to debug and check my problem.
      Thanks

      Comment


      • #4
        You should try to run and debug existing spring social show-case examples depending on what you need.

        See ProviderSignInController class for details.

        It had internal private method which looks like:
        Code:
        private String handleSignIn(Connection<?> connection, NativeWebRequest request, Model model) {
           List<String> userIds = usersConnectionRepository.findUserIdsWithConnection(connection);
           if (userIds.size() == 0) {
           	ProviderSignInAttempt signInAttempt = new ProviderSignInAttempt(
                   connection, socialAuthenticationServiceLocator, usersConnectionRepository);
                request.setAttribute(ProviderSignInAttempt.SESSION_ATTRIBUTE, signInAttempt, RequestAttributes.SCOPE_SESSION);
           	return redirect(signUpUrl);
           } else if (userIds.size() == 1) {
                  usersConnectionRepository.createConnectionRepository(userIds.get(0)).updateConnection(connection);
                  String originalUrl = signInAdapter.signIn(userIds.get(0), connection, request);
                  return originalUrl != null ? originalUrl : postSignInUrl;
        ........
        Code lines:
        if (userIds.size() == 0) {
        ProviderSignInAttempt signInAttempt = new ProviderSignInAttempt(connection, socialAuthenticationServiceLocator, usersConnectionRepository);

        create real record in UserConnections table when User is authorized by FB for the first time.

        Lines:
        } else if (userIds.size() == 1) {
        usersConnectionRepository.createConnectionReposito ry(userIds.get(0)).updateConnection(connection);

        run then User is already known in local UserConnections table and his UC data will be updated by newest info from FB.

        The rest of functionality for registering your local Account and other stuff is out of scope those examples, unfortunately.

        Comment


        • #5
          Thanks for you reply.

          In case I want to do an account using FB or others providers it's OK. But what I want to understand is:
          1. I create an account using simple way, mean no connections FB, Twitter, or others;
          2. I connect to my application using simple Spring Security provider (signin/authenticate),... work OK;
          3. I want to connect using FB, in this case,... SS check in UserConnection table, but, for sure I don't have any connections because of my first time FB connection, so SS will redirect me to signup page.

          Problem I see here is, that in this case,... even if I registered to an application using simple way(no FB, Twitter,....) and then try to connection using FB, it will redirect me again to signup page, but I already have an account.

          Do I misunderstood something?

          Comment


          • #6
            1.
            As I think there is some unique info for identifying your local Account (like email).

            ...even if I registered to an application using simple way(no FB, Twitter,....) and then try to connection using FB, it will redirect me again to signup page, but I already have an account.
            Your new FB/TW user will be redirected to FB/TW in any case...
            At least he must give 'access rights' in his FB/TW account for your application (in FB/TW system)... Then he is redirected back to your app (app page) with some FB/TW profile info returned back.
            You can use that FB/TW account profile data for subsequent check... if that user already has an Account record in your system or no.
            So you can: 1) create new Account, 2) 'connect/reference' Account with newly create UserConnections record using your custom way/code., 3) authorize that user 'automatically' if there is an UserConnections + Account records in your system.

            There is problem related to getting 'email address'. FB returns that data if '&scope=email' is specified. TW does not return it. Every OAuth provider has his own policy about that stuff.

            Comment


            • #7
              Having seen nothing of your configuration, I can't say with any certainty what's going on here. But from your description of the problem, it *sounds* like you're trying to use ProviderSignInController's flow to connect an existing account to FB/Twitter/etc. That is not what ProviderSignInController is for. What you want is ConnectController.

              ConnectController's job is to establish a connection between an authenticated user's *existing* local account and their remote provider account. ProviderSignInController's job is to signin an unauthenticated user based on their remote profile information--and, if no match is found, send them through the signup page to register a new local account.

              Both controllers take the user through a very similar flow, but the outcome is different. ConnectController will insert a row into the UserConnection table. ProviderSignInController will *read* from the UserConnection table to see if there's a match to an existing user and sign that user in.

              Comment


              • #8
                Thanks for your reply and sorry for my bad problem description, hope it's describe better now.

                Example:
                1. I enter first time on the site and create an account using signUp link.
                From the Spring Social Showcase that's Or you can signup with a new account. row.
                My new created account is "ArtyomyuS".

                2. I want to connect via Twitter. My account on twitter has username "ArtyomyuS";
                I press signIn with Twitter and ProviderSignInController check for the user in UserConnections. As of no connections found, it redirect me to signup form, filled in with twitter data. In this case when I'll submit the form, it will show me the error "Username already in use".

                That's ok that I have this error, but hey I want to connect with twitter, and I know that I already have an account on this application..., so it's a bit confusing the users that have already an account and want to connect using an provider.

                Comment


                • #9
                  At step #2, the only way ProviderSignInController can sign-in with Twitter is if the existing account already has a connection with Twitter. You didn't say that you did that in step 1 or at any time prior to step 2, so there is no existing connection. So, as far as ProviderSignInController is concerned, there's no user who can be signed in as the currently authorized Twitter user. Therefore, it takes you to a signup page to register a new user.

                  What your user could have done in between step #1 and step #2 is go to /connect/twitter (that is, kick of the ConnectController flow) to establish a connection between the local user and the Twitter account. Then, when you get to step #2 it would find a matching connection and sign the user in.

                  Another thing you could do is to add a login form to the signin form. That is, offer both options on a single page (lots of websites do this, so I'm sure you've seen something like this). If they fill in the signup form, then they'll create a new user...if they fill in the signin form, then they'll be signed in. Post-signup or post-signin, you can use ProviderSignInUtils to complete the connection to Twitter.

                  Spring Social Showcase shows how to do this post-signup...but not post-signin. Maybe I could update the sample to show that scenario, too.

                  Comment


                  • #10
                    Thanks a lot for your help habuma. Thinking about to manage somehow the Account checking on post-signin.

                    Comment

                    Working...
                    X