I have a page tab app. The authorization works fine - the user clicks the authorize button on the app, the OAuth dialog pops up, they authorize the app, it redirects back to the page tab and the user goes about their merry way, using the app.
I need to know one thing, and for the life of me I cannot find a real answer - is it possible to identify the one http request that occurs immediately after the user authorizes the app? I simply want to log the user's data when a user authorizes the app, without having to hit the database and test if the facebook user id has already been logged. You'd think this would be easy...
THank you for your time.
Yes, you can do with help of the signed_request
Read here how to handle authroization in page tab.
simply, when user comes to app
- check user_id exits in signed request, if not exist, then he has not authorized.
- Store some variable in session
- when user logs in, check whether session variable exists or not. if exists, its a fresh install.
Related
Here is a scenario to explain my question:
Lets say the app is a simple "suggestion box." The company installs the app and adds it to their facebook page. Then a user sees it and decides to leave a suggestion.
Once they click on the app, the app will ask to be authorized. Once they authorize it, I have no trouble sending their FB username to my server.
But how can I capture the user id of the company on whose page they first clicked on the app before they installed it?
I want the app to capture both the username of the person who is authorizing it, and the username of the person on whose page he click on the app.
Some users may install the app from the app center directly, in which case this field may be blank, but every time someone clicks on the app on someone's facebook page, I need both pieces of information to go to the server.
Any ideas?
You'll be able to find this information in the signed_request passed to your application. It contains a page parameter that contains information about the page that the application is installed on. If the page exists, then the user is accessing your application from a page tab, if not, it would be safe to assume that the user is interacting with the application on its canvas url - https://apps.facebook.com/yourAppNamespace
Facebook Signed Requests -
A signed_request parameter is used by Facebook to pass data to an application in a number of different scenarios...
I have an app within which I submit data to Facebook, I have the login and everything working perfectly, storing user credentials in the user defaults upon successful login.
The problem I am having is that there seems to be no way of detecting when a user has logged out of either the Facebook app or using Mobile Safari. This means that my app is tied to one and only one user for its lifetime.
I do not want to put a 'Logout' button in my app, if I had one then I could easily call the logout method and delete the user credentials meaning a new user could authenticate with my app, but that's not a possibility.
Does anyone know of a way I can check if a user is logged in and if so get their Facebook ID? This way I could force authorisation again if either there is no one logged in or the credentials of the logged in user and saved credentials do not match.
Thanks
I think the issue and the confusion here is that FB has implemented "Single Sign On (SS-On)" but not "Single Sign Out (SS-Out)".
The way SS-On works is that if you have previously logged in on your app, you will have the token stored on your app. This means that even though you have logged out on the FB app and perhaps then subsequently logged in as another user, as long as your app still has the token from the previous user, you can still access the previous user data.
What you could do is closeSessionAndClearToken on your app when it goes to background. This might or might not be the desired behavior for you. Note that this means everything your app come back from active from background, it will need to do the whole drill of SS-On all over again everytime.
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[FBSession.activeSession closeSessionAndClearToken];
}
You can use
if([facebook isSessionValid])
{
// 1. Either the user has logged out
// 2. Or the user has changed the password
}
I'm trying to write application for user login to website via Facebook. When user is logging in, he's redirected to http://www.facebook.com/dialog/oauth/?client_id=APP_ID&redirect_uri=REDIRECT_URL&state=STATE, then sees confirmation dialog to use permissions and all goes well. But then FB somehow remembers this application and never asks for permissions confirmation again when user opens this url. Is there any way to always show this dialog? I could do it in Twitter, but couldn't found the answer for Facebook.
If you really want this for some reason, uninstall the app from the user's account with a HTTP DELETE request to /USER_ID/permissions using your app access token.
The next time they come back they'll need to re-authorise the app.
Otherwise, no, there's no way that I'm aware of apart from the reauthentication flow to force the auth dialog to appear, but bear in mind that the reauthentication flow may prompt the user to re-enter their Facebook password even if they're already logged into Facebook, so it adds extra friction to the process
Instead of showing the Facebook OAuth dialog, you could also show the user a page on your application that has some information about the Facebook account that is going to be used (picture/name etc), to log into it. That way, if they like they can choose to log out and re-authenticate or continue knowing they have the right account.
I'm implementing facebook connect for my iPhone app. The current facebook SDK would keep you logged in unless you log out explicitly, which is fine with me as stay logged in is actually the requirement. However, I don't want the users to go press the log in button if they never logged out. In this case, I won't be able to grab the facebook object, which I'll need in other parts of my app. So I was planning to simulate the log in event anyways, but that led me to another problem: even though permissions are granted to my facebook app before, it will still pop up the authorization dialog to my users saying they have granted permissions to my app. My question is, how do I hide this? Or, is there a way that I can grab the valid facebook object without calling authorize on my facebook object when my app is restarted and the user stayed logged in?
Any suggestion would be appreciated.
You could redirect the user to https://www.facebook.com/login.php?api_key=<YOUR_APP_ID>. (This is the URL that the PHP Facebook SDK returns when you call getLoginUrl()).This will avoid the dialog and still allow users to authorize your app.
I am developing and testing a facebook app for which I have granted the permissions with my facebook account. Then the app is authorized to access my info, etc. nicely. The next time I close the browser, reopen it, login to facebook successfully then access the app, facebook wants me to login to that app again. I can access the current user id, but how can I automatically authorize the app (if the user has already authorized in the past) without needing the user to press that dread 'Login' button again and again upon each session's end?
UPDATE - offline_access has been deprecated. Read this post for more details: https://developers.facebook.com/roadmap/offline-access-removal/
You will need to request a token that has offline_access so that you can use their authentication token over and over again. Then you will need to set a cookie yourself that stores something indicating who the user is. Facebook does not support a "remember me" feature in their authentication so you have to build it yourself. Store the access token in your database and set the cookie to identify the user.
Unless you are building this for a very specific reason like an app that runs on work computers only, I would really encourage you to not implement this feature. The facebook connect authorization is well understood by users and is very easy to use. You are going to get a lot more security if you make your users press the button every time. Just make sure you make this optional. You never know if somebody is on a public computer.