Thursday, December 02, 2010

How to support facebook single sign-on in your iphone app

PREPARATION
1. download latest facebook sdk for iOS
2. register your application with facebook: http://www.facebook.com/developers/createapp.php
3. set name and picture for your application (for user to have an idea about the application they are going to authenticate)

HOW TO INTEGRATE FACEBOOK SDK WITH YOUR PROJECT

1. add source code under folder FBConnect to your project
2. include the FBConnect headers in your code
#import "[RELATIVE_PATH]/FBConnect.h"
3. init Facebook object
Facebook* facebook = [[Facebook alloc] init];

WHAT IS SINGLE SIGN-ON?
The new authentication mechanism that users no longer have to re-enter their credentials to authenticate each app if valid session already exists Facebook official app or Safari.

HOW SINGLE SIGN-ON WORKS?
It relies on iOS's fast app switching. Your app trigger FBApp/Safari for authentication. After the user grants or declines the authorization, the FBApp/Safari redirects back to your app, passing the authorization token, expiration, and any other parameters the Facebook OAuth server may return.

SINGLE SIGN-ON FLOW


SUPPORT SINGLE SIGN-ON
1. bind your app to a URL scheme corresponding to your Facebook application ID by modifying .plist file of your app

2. catch FBApp/Safari redirection by implementing this in your app's main AppDelegate
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{
[facebook handleOpenURL:url];
}


START AUTHENTICATION
1. call authorize method
[facebook authorize:{YOUR_APP_ID} permissions:{PERMISSIONS} delegate:self];


HOW TO DISABLE SINGLE SIGN-ON?
1. in Facebook.m authorize method
[self authorizeWithFBAppAuth:NO safariAuth:NO];


ref: https://github.com/facebook/facebook-ios-sdk/

No comments:

Post a Comment