Recently, I followed https://help.salesforce.com/HTViewHelpDoc?id=sso_provider_facebook.htm&language=en_US to set up a facebook auth.provider, and put the callback URL in my facebook app. The provider is using a custom handler shown below.
After the user logs in using facebook credentials, I always get a null value for access token using the following in the handler:
Auth.AuthToken.getAccessToken('my auth.provider id in org', 'Facebook');
I even tried using Salesforce facebook app instead of mine, but still no luck. Can some one tell me if there is something specific I need to pay attention to to get access token?
public class FacebookHandler implements Auth.RegistrationHandler{
public User createUser(Id portalId, Auth.UserData data){
User[] users = [SELECT Id FROM User WHERE Email = :data.email];
if (users.size() == 0) {
String accessToken = Auth.AuthToken.getAccessToken('0SO28000000XXXXXX', 'Facebook');
System.debug('access token: ' + accessToken);
return null;
}
else if (users.size() == 1)
{
User u = users[0];
System.debug('User Id: ' + u.Id);
String accessToken = Auth.AuthToken.getAccessToken('0SO28000000XXXXXX', 'Facebook');
System.debug('access token: ' + accessToken);
//return the user to login as
return u;
}
return null;
}
Many thanks in advance,
Jun Liu