agorapulse / grails-facebook-sdk

Facebook SDK Grails Plugin
http://agorapulse.github.com/grails-facebook-sdk/guide
30 stars 13 forks source link

request.facebook.authenticated is false for production server (EC2) #6

Closed alankala closed 12 years ago

alankala commented 12 years ago

I'm using facebook-sdk grails plugin in my Grails project to integrate with Facebook. I followed steps mentioned in https://github.com/benorama/facebook-sdk-grails-plugin. My code works fine on my localhost. But when I deploy the code to our production Amazon EC2 server, "request.facebook.authenticated" is false even though I Allow access to an App. My redirect_uri from facebook on successful authentication calls connectToFacebookCallback method correctly, but request.facebook.authenticated is false. This code works fine on my localhost.

Is there anything specific setup that needs to be done for EC2.

I'm currently stuck with this. Any help is highly appreciated.

Thanks, Akhila.

My code - view.gsp -

// Put here any JS code to be executed after Facebook JS initialization /facebook:initJS Login You are not Connected.

controller.groovy corresponding to this gsp page - {..... def onLoad() { //this code is called when the above gsp is loaded if(request.get) { // Login or logout url will be needed depending on current user state. String loginUrl = null; if (request.facebook.authenticated) { String facebookId = request.facebook.user.id.toString(); if (request.facebook.app.id) { loginUrl = getLoginUrl(); } ...... } else { loginUrl = getLoginUrl(); } return [loginUrl:loginUrl] } def connectToFacebookCallback() { FacebookGraphClient facebookGraphClient = new FacebookGraphClient() def user if (request.facebook.authenticated){ try { ......... System.out.println("i'm here"); } catch (FacebookOAuthException exception) { System.out.println("exception auth"); System.out.println(exception.printStackTrace()); // Usually an invalid session (OAuthInvalidTokenException), for example if the user logged out from facebook.com facebookAppService.invalidateUser() facebookGraphClient = new FacebookGraphClient() } } else { System.out.println("user dint auth in fb...clicked cancel"); } } private String getLoginUrl() { String currentURL = "http://:/connectToFacebookCallback"; String loginUrl = facebookAppService.getLoginURL([scope:request.facebook.app.permissions, redirect_uri:currentURL]); return loginUrl; } Config.groovy contains entries for facebook.appid and appsecret.
benorama commented 12 years ago

You might try to add logging to see what's going on. Add debug 'grails.plugins.facebooksdk' to your Config.groovy.

You might also try to use Facebook JS SDK login which is more user-friendly than Facebook server-side redirect (see demo app).

alankala commented 12 years ago

One caveat I have with my use-case is...my server has no actual domain name. It only has IP. But I got a hostname which simply redirects to this ip address. Can this cause the filters not to set correctly. I was reading one of the issues mentioned here - https://github.com/benorama/facebook-sdk-grails-plugin/issues/4

On Thu, May 24, 2012 at 12:36 AM, Benoit Hediard reply@reply.github.com wrote:

You might try to add logging to see what's going on. Add debug   'grails.plugins.facebooksdk' to your Config.groovy.

You might also try to use Facebook JS SDK login which is more user-friendly than Facebook server-side redirect (see demo app).


Reply to this email directly or view it on GitHub: https://github.com/benorama/facebook-sdk-grails-plugin/issues/6#issuecomment-5894473

benorama commented 12 years ago

You might try to use Facebook JS SDK login instead of server redirect. Hostname resolution might cause some issue in Facebook server side redirect.

benorama commented 11 years ago

Hi Akhila,

FYI, I'm going to release pretty soon Facebook SDK V0.4. The main objective was to "clean" the SDK code which was pretty messy (since it was a port of PHP code...). The other objective was to be able to support multiple Facebook app within a single Grails app. It's pretty big refactoring of the code base.

Unfortunately, it won't be backward compatible with V0.3.* ... FacebookApp, FacebookSdkFilters and FacebookAppService have been deprecated and replaced by a single FacebookContext bean: a cleaner approach to access Facebook context info (current app, user, page...) So if you use any of them, you might have to do some refactoring on your app.

I'm looking for some feedback, if you have some time to play with it, it's on "develop" branch. You can download the updated docs here : http://cl.ly/2q2T300G201J

Thanks !

Ben

alankala commented 11 years ago

Thanks Ben for letting me know. I'll try to download the build and let
you know my feedback soon.

Thanks Akhila

On Sep 23, 2012, at 1:49 PM, Benoit Hediard notifications@github.com
wrote:

Hi Akhila,

FYI, I'm going to release pretty soon Facebook SDK V0.4. The main objective was to "clean" the SDK code which was pretty
messy (since it was a port of PHP code...). The other objective was to be able to support multiple Facebook app
within a single Grails app. It's pretty big refactoring of the code base.

Unfortunately, it won't be backward compatible with V0.3.* ... FacebookApp, FacebookSdkFilters and FacebookAppService have been
deprecated and replaced by a single FacebookContext bean: a cleaner
approach to access Facebook context info (current app, user, page...) So if you use any of them, you might have to do some refactoring on
your app.

I'm looking for some feedback, if you have some time to play with
it, it's on "develop" branch. You can download the updated docs here : http://cl.ly/2q2T300G201J

Thanks !

Ben

— Reply to this email directly or view it on GitHub.