Announcement Announcement Module
Collapse
No announcement yet.
Setting the Username for Facebook Logins with Implicit Sign Up Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Setting the Username for Facebook Logins with Implicit Sign Up

    For my project that requires implicit sign-up, I began by implementing login with Twitter. My implementation of the ConnectionSignUp's execute method looked like this:

    Code:
    public String execute(Connection<?> connection) {
            UserProfile profile = connection.fetchUserProfile();
            
            // This method returns a Twitter screen name, but for Facebook it returns null
            String username = profile.getUsername();
            User user = new User( username, profile.getFirstName(), profile.getLastName(), new DefaultRole() );
            this.userService.create( user );
            return username;
        }
    This works fine for Twitter, because the profile.getUsername() returns the Twitter screen name.

    Right now I'm trying to add login with Facebook. The problem I'm facing is that the profile.getUsername() method is returning null, which means that the user's record is not inserted into the UserConnection.

    I'm looking for a suggestion of my best bet for setting a logical username for a Facebook user.
    Last edited by alexduff; Jul 12th, 2013, 06:58 AM.

  • #2
    Well, I gotta ask: Does the user *have* a username? Not all FB users have a username. I do, but my wife doesn't. I don't recall exactly what I went through to set this up, but I seem to recall that in order to get a username, you must be a verified user and to be a verified user you have to provide FB with your phone number so that they can text you a verification code. (I think the same thing is required to create applications in FB.)

    So, if you're looking for a username from FB, I don't think you can rely on it always being available. The user ID (profile.getId() ) *is* always available, so I'd use that.

    Comment


    • #3
      Craig,

      Thanks for your response. After reading your post and a bit more testing, I realized that profile.getUsername() is returning the Facebook username if it exists. So my challenge is not a general "how do I create implicit sign-in usernames" for Facebook logins, my challenge is specific to Facebook logins for users that do not have Facebook usernames.

      At present, my requirements for the usernames in my application are fairly limited:

      1. Obviously I want to avoid username collisions within a given provider.
      2. I display the username to the user when the user visits my site.
      3. I am using the username within my RememberMe cookie.

      So with that in mind, I think I can build some logic that automatically generates a username for this subset of Facebook users using their first and last names (and gracefully handling collisions).

      Cheers,
      Alex

      Comment

      Working...
      X