In some cases an application has to integrate with another one in order to access information that this application manages.
In other cases there's a simply a security policy which establishes that the application users have to be valid users in any other web site or application.
In order to integrate to Facebook, just follow these steps:
1. You need to create a "Facebook client application" in Facebook site and obtain App Id and App Secret for that application.
Go to Facebook for developers (http://developers.facebook.com/) -> Applications -> Creat new application, as shown in the following figures:

Figure 1.

Figure 2.

Figure 3.
Set in "Select how your app integrates with Facebook" the part "Website" option and set Site URL = http://<domain> (http://apps2.genexusx.com) and Site domain your domain (eg.: apps2.genexusx.com).
You do not need to set the options in part "Mobile and Devices" since GeneXus SD Apps redirect to a browser in order to insert your credentials.
2. Define "Facebook Authentication Type" using the GAM backend. Note that "gamhome" is the GAM backend main object and you have to go through Authentication Types link.

Figure 4.
Facebook API needs the SITE URL to be public and without any port (default port = 80), so if your application is hosted under port 8080 for example, you need to use any kind of proxy or similar (like Apache web server) in order to use port 80.
Important note:
In case of Java and NET you need to enter the complete site URL in Site URL. For example: http://apps2.genexusx.com/Ide1b858bf3b044ba0ac777119780e4370/servlet (Java) or http://apps3.genexusx.com/Ide1b858bf3b044ba0ac777119780e4370 (.NET)
In case of Ruby you need to specify in SITE URL only the server, not the complete URL, for example: http://apps2.genexusx.com
For more details about this see the information at the bottom of this page.
Facebook Authentication Type can be used in Web Applications and in Smart Devices applications also.
Web Applications
In case of Web Applications, the GamExampleLogin object (which is part of the GAM example library) includes automatically a button by which the user can login to Facebook.
This button is included dinamically, as the Facebook Authentication Type is detected to be defined in the GAM Repository.

Figure 5.
SD Applications
In case of Smart Devices applications, you need to change the "Login Object for SD" (it is at the Version level and has the "GAMSDLogin" default value) and add a button which will be specifically for this type of authentication.
The logic inside the event associated to this button will include a call to a method of SDActions, named "LoginExternal".
The first parameter this method recevies, has to take its value from the Type name defined in the "Authentication Type" definition of the GAM Repository ("Facebook") - see Figure 4.
Event 'facebook'
SDActions.LoginExternal("Facebook","","")
EndEvent
There´s no need to define variables for the parameters, because in this case the only important parameter of "LoginExternal" Method, is the first parameter which value is "Facebook" always.
As happens in web applications, when tapping the "Facebook" button, the Facebook login appears in the device and after you have logged in, the application will load.
What happens really is that after the user authenticates in Facebook, the application redirects to "GAM application" where the user is created using the credentials given to Facebook, and it generates a Session in GAM. User´s data is updated taking the information from Facebook in each new login.
After a user has logged in with facebook, his information can be seen looking at the "Users" information using the GAM Backend.

Figure 6.
In case you want to work with friends, or do any particular action after the user has logged in, you need to comunicate with the Facebook API.
iOS 6.0 Facebook Integration
One of the main features of iOS 6.X is that the operating system has a much better integration with social apps such as facebook. You can see more information about this here -> http://www.apple.com/ios/whats-new/#facebook

To accompany this progress GeneXus Acces Manager has also turn into a much more integrated product with iOS 6.X and Facebook.
From GeneXus Evolution 2 Upgrade 3 when the Facebook authentication type is configured in iOS devices with iOS 6.X the behaviour will be the following:
a. If the device has the Facebook app and it is logued, the Log In with Facebook will not ask the user and pasword it will get the credentials from the device
b. If the device doesnt have the Facebook App but in Settings/Facebook is logued in with a Facebook account the login will not prompt for the user and password it will take the credentials from the device
The user will be prompted the following message:

c If the user is not logued in on the settings and is not logued on the Facebook app but it is installed the following login screen is going to be shown.

d. If the device doesnt have the Facebook App or the user is not logued in the Facebook App or in the OS option, the facebook login will work as always invoking a web login to insert the user and password.

e. If the device has a prior version of iOS it will work like it always did. Same as step d.
How to configure this new iOS integration?
The only additional step that is needed is to attach the iOS native app with the facebook app.
This can be done in the following screen:

And in GeneXus, on the main properties of your start up object:
Set the Facebook API

Note:
1. Facebook Authentication is solved using OAuth.
2. The &Session.ExternalToken (&Session is GAMSession type and corresponds to the session obtained after the user has logged in) has to be passed to the Facebook API to do any of the desired actions (as getting the user friends, etc).
See Also
GAM: Facebook Interaction Sample
How to deploy to cloud Java and Ruby applications using Facebook Authentication
Prototyping applications with Facebook or Twitter Authentication
GAM Twitter Authentication Type
Additional Scope Property for GAM Google / Facebook Authentication Types
|