Nirav Shah
Nirav Shah

Reputation: 689

Having Different Callback actions in OmniAuth

I am using Omniauth and Fb_graph gems in my app.

I wanted to perform two different actions on:

1) Sign up using facebook -> Using Omniauth I create an authentication and redirect to root_path

2) Finding facebook friends -> If an authentication exists, find friends using fb_graph. If it doesn't exist, create an authentication in omniauth and then redirect to fb_friends_path

How can I have different callbacks after authenticating using Omniauth? (In first case, I want to redirect to root_path and in second case I want redirect to fb_friends_path after creating an authentication if it does not exists.)

Thanks a lot!

Upvotes: 1

Views: 692

Answers (1)

tlbrack
tlbrack

Reputation: 926

Assuming you are using rails, setup a before filter called :auth_required that checks to see if that user has setup authorization in the past -- perhaps you are storing oauth tokens and you can check for it. Place :auth_required in front of the action that corresponds to fb_friends_path. If they don't have authorization setup, store the user's intent (their desired url) in the session.

In the callback you have setup for omniauth, if there is a stored intent redirect to it and remove it. Otherwise, assume they are signing up and send them to the root path.

Upvotes: 1

Related Questions