Page 1 of 2 12 LastLast
Results 1 to 10 of 20

Thread: Facebook Provider Sign-in Problem.

  1. #1
    Join Date
    Mar 2012
    Location
    San Francisco
    Posts
    12

    Default Facebook Provider Sign-in Problem.

    Good day ,

    I am having a small problem with my web app . I am trying to use spring social to provide a Facebook login feature for my app. I have a database with my local users accounts (PostgreSQL) and I'm using hibernate .

    So far this is what i have accomplished. When a user comes to the sign in page , he/she can login using their username and password or click a <Sign-in with Facebook> button. When they click the button it posts to /signin/facebook and the ProviderSignInController kicks in and connects to Facebook , does the authentication and then sends the user to the signup page where it pre-fills some the fields (First Name , Last Name , email address) from the Facebook profile. they can then fill out the remaining fields and submit , where it saved to my database. I have a field in my database account table that stores the Facebook userid.

    My problem is now , even after the account is created , when i click the <sign-in with Facebook> button , after it does the authorization by Facebook and redirects , it still doesn't make the link to the local user account , and prompts the user to sign up again .

    I know where my problem lies , its a matter of how to fix it . I am trying to figure out how exactly the providersignincontroller tries to match the Facebook account to my local users account.

    Any help will be greatly appreciated.

    Thanks.

  2. #2
    Join Date
    Nov 2011
    Posts
    10

    Default

    Based on what you said first I would check UserConnection table which maps your local userid to the providerUserid. If that is looks good I would then check SignInAdapter which you provide to ProviderSignInController. ProviderSignInController will call your SignInAdapter's signIn method where you have to do the user login yourself by populating the securityContext.

    This might help GitHub - Spring Social Showcase and Social Config
    Last edited by binnyg; Apr 7th, 2012 at 04:07 PM.

  3. #3
    Join Date
    Aug 2004
    Posts
    1,067

    Default

    You say you have an account table that includes the Facebook user ID...that's fine if it helps your application code somehow, but that's not enough for Spring Social. Spring Social wants to manage connections in a UserConnection table. This table essentially joins the application-specific user ID with a provider (e.g., Facebook, Twitter) account as well as a few other bits of info about the connection.

    After your code saves the new account info to the database, do you follow that up with a call to ProviderSignInUtils.handlePostSignUp()? If not, then the connection is never created in the UserConnection table.

    For example, the Spring Social Showcase example has the following code that handles the signup form submission:

    Code:
    	@RequestMapping(value="/signup", method=RequestMethod.POST)
    	public String signup(@Valid SignupForm form, BindingResult formBinding, WebRequest request) {
    		if (formBinding.hasErrors()) {
    			return null;
    		}
    		Account account = createAccount(form, formBinding);
    		if (account != null) {
    			SignInUtils.signin(account.getUsername());
    			ProviderSignInUtils.handlePostSignUp(account.getUsername(), request);
    			return "redirect:/";
    		}
    		return null;
    	}
    Notice near the end, after the account has been created successfully (and is not null), the code uses SignInUtils to automatically sign the user into the application and then uses ProviderSignInUtils.handlePostSignUp() to complete the connection between the newly created user and the provider (e.g., Facebook).
    Craig Walls
    Spring Social Project Lead

  4. #4
    Join Date
    Mar 2012
    Location
    San Francisco
    Posts
    12

    Default persistent storage of userConnections

    hi , i solved the problem using the information you provided. Thank you very much . I understand where the users connection comes into play now. however one thing though . if i restart my server the user connections are lost. how can i save these connections to a table in my db ?

  5. #5
    Join Date
    Aug 2004
    Posts
    1,067

    Default

    With Spring Social Showcase, it's using an in-memory database, which is great for demos and development, but horrible for production for the reasons you've just given. I'm assuming that the reason your connections are lost is because you're using the embedded database. Rather than use the embedded database, you should use a datasource that's tied to a real DB.
    Craig Walls
    Spring Social Project Lead

  6. #6
    Join Date
    Mar 2012
    Location
    San Francisco
    Posts
    12

    Default

    Thank you Craig , I got it working by creating the userconnection table in my db and pointing the datasource to it. Everything works fine now. The only thing i noticed when i created the table is that i had to change refreshtoken and secret fields from not null to allow nulls because this was throwing an error.

    Thanks again for your help.

  7. #7
    Join Date
    Aug 2004
    Posts
    1,067

    Default

    Hmmm...those columns are already defined to allow nulls, per JdbcUsersConnectionRepository.sql:

    Code:
    create table UserConnection (userId varchar(255) not null,
    	providerId varchar(255) not null,
    	providerUserId varchar(255),
    	rank int not null,
    	displayName varchar(255),
    	profileUrl varchar(512),
    	imageUrl varchar(512),
    	accessToken varchar(255) not null,					
    	secret varchar(255),
    	refreshToken varchar(255),
    	expireTime bigint,
    	primary key (userId, providerId, providerUserId));
    create unique index UserConnectionRank on UserConnection(userId, providerId, rank);
    Craig Walls
    Spring Social Project Lead

  8. #8
    Join Date
    Mar 2012
    Location
    San Francisco
    Posts
    12

    Default

    ok thanks. i have another question , i have the provider sign-in working perfectly now , i now want to add some additional Facebook functionality to my app , however if i use connect/facebook it creates an additional connection in my user connections table which i do not want. i know i can simply extract the access token from the table and use it , but i want to use spring social functions .

  9. #9
    Join Date
    Aug 2004
    Posts
    1,067

    Default

    I'm not clear on what you're saying...are you saying that you use Provider Sign-In for authenticating into your app (which creates a connection if one didn't already exist) and then go through the ConnectController flow again (which would create another connection)? If so, that's not how it was intended to be used.

    The idea is that if the user has previously created a connection with ConnectController, then they can sign in to the application using ProviderSignInController and not have to enter their app credentials...the previously-established connection will serve as authentication. But, if they haven't created a connection before, then ProviderSignInController can let them sign in via Facebook (or some other provider) and create a new account that is already connected to the provider. There would be no need to go through the connection flow again, because the account would already be connected to the provider (Facebook, in your case).

    If that's not what you're saying, then please clarify.
    Craig Walls
    Spring Social Project Lead

  10. #10
    Join Date
    Mar 2012
    Location
    San Francisco
    Posts
    12

    Default

    I'm sorry if i didn't make myself clear. what I really wanted to find out is how to get extract a Facebook connection from the users connection repository so i can create a Facebook template object and perform Facebook operations. I have already realized that i don't need to to use connectController. at present what i do is manually retrieve the accesstoken from my userconnection table and then create the Facebook template object from that.

Tags for this Thread

Posting Permissions

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