TomGrill / gdx-facebook

libGDX extension providing cross-platform support for Facebook Graph API.
Apache License 2.0
60 stars 21 forks source link

Auto-login to facebook gives unnecessary "already authorized this app" confirmation popup on android #3

Closed StanDem closed 9 years ago

StanDem commented 9 years ago

This even happens on GdxFacebookSampleApp. If I enable auto-login to call loginWithReadPermissions on app start, the " already authorized this app " poup confirmation dialog appears every time.

I guess you should just use the existing token instead of login again. I've noticed it is saved in the .session file on android. But It would be great to have proper auto-login handling inside your class.

TomGrill commented 9 years ago

this should not happen, will look into this asap. There were some changes in the FB 4.x API compared to 3.x maybe this messed it up.

TomGrill commented 9 years ago

Reason for this was that when the user did not have installed the Facebook App then the Facebook SDK will use a fallback modus which seems not to reuse existing tokens. I added a token storage solution. Should work with 0.5.0-SNAPSHOT now.

Please test and give feedback.

StanDem commented 9 years ago

Thank you.=) But, have you changed something concerning class configuration? Because in my project with the same code or even your gdx-facebook-app I'm getting this error after updating to 0.5.0-SNAPSHOT:

I'm getting instant crash on android: E/AndroidRuntime﹕ FATAL EXCEPTION: GLThread 195 java.lang.NullPointerException at de.tomgrill.gdxfacebook.core.GDXFacebook.(GDXFacebook.java:50) at de.tomgrill.gdxfacebook.core.FallbackGDXFacebook.(FallbackGDXFacebook.java:26) at de.tomgrill.gdxfacebook.core.GDXFacebookSystem.installSystem(GDXFacebookSystem.java:60) at de.tomgrill.gdxfacebook.core.GDXFacebookSystem.install(GDXFacebookSystem.java:70)

On Desktop there's no crash at app start, but I can't login,

java.lang.NullPointerException at de.tomgrill.gdxfacebook.desktop.DesktopGDXFacebook$3$1.onSuccess(DesktopGDXFacebook.java:117)

TomGrill commented 9 years ago

pls check your GDXFacebookConfig and make sure PREF_FILENAME is not empty or null

StanDem commented 9 years ago

As I can see - public String PREF_FILENAME = ".gdxFacebookTokenData"; by default. Anyway file is being created properly(at least on Desktop), so I think there's something related to new features. e.g error line from my message above (#117) pointing at long issuedAt = data.get("issued_at").asLong() * 1000;

TomGrill commented 9 years ago

I have added a System.out.println() to line 109 so see what FB returns. I dont get errors. Can you copypaste the output please? (X the app_id and user_id)

Should look like this: {"data":{"app_id":"XXXXXXXXXXXXX","application":"Gdx Example App","expires_at":1444139202,"is_valid":true,"issued_at":1438955202,"scopes":["user_friends","email","publish_actions","public_profile"],"user_id":"XXXXXXXXXXXX"}}

StanDem commented 9 years ago

Ok. I've updated android fb sdk to 4.4.0 and set the config.PREF_FILENAME = ".facebookSession"; Now it works for Android. But If logout and then try to login again - it doesn't ask for user name and password, just login. If the user wants to change an account, this could be a problem. Please check what you can do about it.

On Desktop I'm still getting the error. With your gdx-facebook-app (unchanged, as it is): STORE TOKEN: {"token":"XXXTOKENXXX"} {"error":{"message":"(#100) You must provide an app access token or a user access token that is an owner or developer of the app","type":"OAuthException","code":100}} GdxFacebookSampleApp: READ REQUEST: Error login: (#100) You must provide an app access token or a user access token that is an owner or developer of the app

With my app id: STORE TOKEN: {"token":"XXXTOKENXXX"} {"data":{"app_id":"xxxx","application":"OceanuX","expires_at":1438970400,"is_valid":true,"scopes":["user_friends","email","publish_actions","public_profile"],"user_id":"xxx"}} GdxFacebookSampleApp: READ REQUEST: Technical error occured: java.lang.NullPointerException at de.tomgrill.gdxfacebook.desktop.DesktopGDXFacebook$3$1.onSuccess(DesktopGDXFacebook.java:117) at de.tomgrill.gdxfacebook.desktop.DesktopGDXFacebook$3$1.onSuccess(DesktopGDXFacebook.java:104)

TomGrill commented 9 years ago

thanks, good input with switching accounts. I will try to get things to work this weekend.

TomGrill commented 9 years ago

Please try latest version.

FB token_debug is now filtered and should no longer throw NullPointerExceptions when incomplete. This should fix the problem on desktop.

Android: After logout and then login user will get prompted again with login screen. However when the user has the Facebook app installed he will immediately gets logged in. I did some research and it looks like with SDK 4.0 you cannot switch users when FB App is installed.

If your app really needs user switching you could try revoking the permissions for your app and then ask again. This should always prompt the FB login dialog. (Not reccomended)

StanDem commented 9 years ago

Ok, now everything is perfect in Desktop version! But on Android I'm still not prompted after logout\login. No Facebook app is installed. Also I will test this for iOS later.

TomGrill commented 9 years ago

On my testdevice I get prompted each time I logout. So currently handcuffed... Did you refresh gradle dependencies etc.?

StanDem commented 9 years ago

You was right. But I had to delete gradle .caches manually to force re-download dependencies. Now I can confirm that everything works as expected on Android. (Logout\login prompts user to re-enter password.)

But... Just made a test on iPad (with cleared caches of course). After logout/login, app shows "already authorized this app" confirmation popup instead of prompting for login/password. No Facebook app is installed. Tested with your fb test app.

TomGrill commented 9 years ago

Afaik iOS SDK uses the safari browser which probably stores the facebook login in cookies. No idea how I can prevent this atm.

StanDem commented 9 years ago

I have checked several popular iOS games, which uses facebook (e.g. candy crush saga) and saw the same behavior. I think you can close this issue. Thank you again for the amazing work =)