One of the basic things that a Facebook canvas app needs to do is check for permissions and require a user to authorize them to access a page. What’s a good way to do this?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Here’s a system I developed for my own apps. You can download the code from:
http://developsocialapps.com/permissions-and-basic-graph-api-calls/
This is the library that does the heavy lifting. The main method to check permissions is requireAuthorization. This will first use initOauthUserFromSignedRequest to see if there is a signed_request to see if the use is authenticated and set the userid and token. It will then use hasAllPermissions to check me/permissions from the graph API to see if the user has all the required permissions. Because I don’t want to hit this API on every page load, I store the permissions in a cookie. If the user doesn’t have the permissions or is not authorized, it directs the user to the authorization dialog.
Use it on a page like this:
redirect.php is a page that will detect if the user has accepted or canceled the authorization. If accepted it will redirect back to the first page, if canceled, it will display a message.