Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I specify the Facebook permissions (aka scope) OmniAuth asks for DYNAMICALLY?

This question is similar to How can I specifiy what access I need from my user's Facebook accounts when using OmniAuth? but has a caveat.

I'm using OmniAuth to authorize Facebook users on my website. For regular login/registration, asking the user for standard Facebook permissions are acceptable. But there is a feature on my site that requires extended permissions (access to their Facebook photos). I want to only ask for the extended permissions for users when/if they use our site's Facebook photo feature.

All answers I've found on the web on how to set facebook permissions for omniauth deal with just adding a scope option in your OmniAuth initializer, like so:

ActionController::Dispatcher.middleware.use OmniAuth::Strategies::Facebook, 'app_id', 'app_secret', {:scope => 'email,offline_access,the,scope,you,want}

But I need to define the scope dynamically, so that only when users use the photo feature they get asked for the photo permissions, but not if they are just logging in or registering for the first time.

Anyone know how to do this? Thanks in advance.

like image 409
Sean Ahrens Avatar asked Jan 20 '11 19:01

Sean Ahrens


People also ask

How do I give an app permission on Facebook?

Tap in the top right of Facebook. Scroll down and tap Settings. Go to the Permissions section and tap Apps and Websites. Go to Apps, Websites and Games and tap Edit.

What is OmniAuth?

OmniAuth is a library that standardizes multi-provider authentication for web applications. It was created to be powerful, flexible, and do as little as possible. Any developer can create strategies for OmniAuth that can authenticate users via disparate systems.

What is Facebook API?

What is the Facebook API? The Facebook Graph API is an HTTP-based API that allows developers to extract data and functionality from the Facebook platform. Applications can use this API to programmatically query data, post in pages and groups, and manage ads, among other tasks.


2 Answers

You may have figured out a solution to this problem already but I figured I'd chime in for those still looking to solve this. My solution allows you to request as little Facebook permissions as possible up front, and then dynamically request them as your app needs them.

http://www.mikepackdev.com/blog_posts/2-Dynamically-Requesting-Facebook-Permissions-with-OmniAuth

Hope this helps!

like image 150
Mike Avatar answered Oct 13 '22 01:10

Mike


It looks like they're adding that to Omniauth, but it's still in beta.

You add a

:setup => true

to your provider and then create a method where you dynamically sets the options (credentials/scope) you need.

https://github.com/intridea/omniauth/wiki/Setup-Phase

https://github.com/intridea/omniauth/wiki/Dynamic-Providers

like image 22
johnnymire Avatar answered Oct 13 '22 01:10

johnnymire