8

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?

Hayk Saakian
  • 2,036
  • 2
  • 18
  • 31

1 Answers1

2

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.

Kristofer Sommestad
  • 3,061
  • 27
  • 39
  • thanks for the answer. i've learned a lot more back end development since i asked that question, and the facebook sdk has also improved. I asked this question because my biggest concerns about the whole process were UI/UX related. Could a similar process be smoother with other SSO systems like with Google or Twitter? – Hayk Saakian Oct 06 '12 at 21:54
  • On iOS 6, the Twitter and Facebook SSO are very much the same and does allow you to provide a smooth reg process (that's pretty much the whole point of them integrating it into iOS itself). Not exactly sure how Google's process works, but I'd guess they're all pretty much the same (even though Google is less supported on iOS). – Kristofer Sommestad Oct 08 '12 at 10:56