Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook SSO and Third Party site registration in one step?

Yes/No + more question:

Is it possible to use the Facebook SSO system and simultaneously register a user for your own website/app?

As in requiring just one keypress on the part of the user.

Also, are there working examples of this on iPhone and Android?

From what i've read, there's a process for doing SSO and a separate process for doing registration.

The reasoning is that I'd like to keep my own record of user data in addition to what facebook gives me through the Insights system, BUT i would like to make this as painless as possible.

t;;dr has this been done before, what are some examples, and any useful and relevant documentation available?

like image 797
Hayk Saakian Avatar asked Jul 24 '11 01:07

Hayk Saakian


People also ask

What is the third-party app for Facebook?

A third-party authentication app (such as Google Authenticator or LastPass) can be used to generate login codes that help us confirm it's you when you log in from a new device for the first time. Install a third-party authentication app on your device.


1 Answers

Not really sure I understand you correctly, but assuming that you want to register a user in your own system without presenting a separate reg flow (?), you can do the following:

  1. Ask user to authorize your app (i.e. through SSO or the regular FB flow – using the latest Facebook SDK will trigger the appropriate flow). Be sure to ask for any extra permissions you'll need for your own signup.
  2. Once your app's been notified about the Facebook authorization, extract whatever user data you need for registration through Facebook's API (i.e. using the graph path /me?fields=id,name,email to get FB id, name and email). The Graph API Explorer is good for checking which fields you can get.
  3. Use the response from (2) to make a POST to your own system to create an account.
  4. Once your account creation request has finished, allow user to start doing whatever he's supposed to in your app (= you're all set!). And possibly save some kind of account identifier in the client (the device), should you need it later.

To make this flow seamless to the user, you should probably show a loading/progress indicator during steps 1-4.

Facebook's SDK documentation should get you going with step (1).

Some sample (Objective-C) code for step (2) and partly (3):

- (void)facebookUserAuthorized
{
    [FBRequestConnection startWithGraphPath:@"me"
                                 parameters:[NSDictionary dictionaryWithObject:@"id,name,birthday,first_name,last_name,gender,email" forKey:@"fields"]
                                 HTTPMethod:@"GET"
                          completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
                              NSDictionary *userData = (NSDictionary*)result;
                              [self registerUserWithEmail:[userData objectForKey:@"email"]
                                               facebookId:[userData objectForKey:@"id"]
                                                   gender:[userData objectForKey:@"gender"]];
                          }];
}

- (void)registerUserWithEmail:(NSString*)email facebookId:(NSString*)facebookId gender:(NSString*)gender
{
    // Send a POST to your own server with the user details
}

And I'm sure you can apply the same principle on Android. Check out Facebook's Android docs to get started.

like image 87
Kristofer Sommestad Avatar answered Nov 15 '22 00:11

Kristofer Sommestad