package net.theliveweb.facebook; import javax.security.auth.login.FailedLoginException; import javax.servlet.http.HttpServletRequest; import com.facebook.api.FacebookParam; import com.facebook.api.FacebookXmlRestClient; /** * Class for handling facebook authentication. Can either be invoked from the filter, * or can be used stand alone * @author theliveweb.net * */ public class FaceBookAuthHandler { public static FacebookXmlRestClient getAuthenticatedClient(HttpServletRequest request, String apiKey, String secretKey) throws Exception { String authToken = request.getParameter("auth_token"); String sessionKey = request.getParameter(FacebookParam.SESSION_KEY.toString()); FacebookXmlRestClient fbClient = null; if (sessionKey != null) { fbClient = new FacebookXmlRestClient(apiKey, secretKey, sessionKey); } else if (authToken != null) { fbClient = new FacebookXmlRestClient(apiKey, secretKey); } else { throw new FailedLoginException("Session key not found"); } fbClient.setIsDesktop(false); fbClient.auth_getSession(authToken); return fbClient; } }