Bypassing devise signin when user registered via REST call - ruby-on-rails

I am using devise with rest enabled. I have a form that requires user authentcation / registration. The authentication is implemented in fancybox light box.
I am able to register and signin using ajax calls. Sign in seems to return a session_id. How do I get the session object after registration. Or, more like is a session object created at registration?
If one is not created how would I bypass signin the first time after registration ?

There seems to be no straight forward way to do this. As of now the only way I can do this is by refreshing the page.

Related

OmniAuth::Strategies::OAuth2::CallbackError user_cancelled_login | The user cancelled LinkedIn login

So I am developing a Rails application with LinkedIn authentication. The application works fine in all the cases except the case when user cancels the login.
I have already visited all the solutions on this site could possibly help, but no luck.
I have designed a very basic login structure and I couldn't understand where to write the code to handle the exception and to redirect the failure to a particular path.
The process I have used to make my login page was: Adding gem, Adding a route to 'auth/linkedin/callback', Adding that controller, Adding omniauth.rb file with provider, client id, key, scope and fields parameters.
Adding from_omniauth method in user model.
And finally the link in view page. Here I have no idea what to manipulate to handle the params error. Thanks
error

Devise/Rails - Access cookie information before creating user

When registering new users via Devise in Rails 5, I need to check if a cookie exists and if so store data from the cookie to a newly created user record. It also utilizes OmniAuth to create users from Facebook. I'm having trouble finding a way to tap into Devise's user creation and be able to access cookie information.
If I implement this directly in the RegistrationController after a user is created, I have to repeat it in the OmniAuth callbacks, which is not very DRY. Is there a better place or method to hook into this?
I came across the new_with_session method when building a new resource, but unfortunately that only gives access to the session, not cookies.

intercepting Omniauth callback with javascript in Rails

I am trying to implement Omniauth and Devise with multiple providers in Rails 3.2 app.
One tricky scenario is: user signs in via LinkedIn for the first time. Since linkedin does not provide user email, I won't know which account I should link this linkedin credentials to. So I want to intercept the callback to prompt a popup window that allows user to enter his email or username, before passing the credentials together with email to controller.
How should I go about this?

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!
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.

How do I tell which authentication user is using in rails (OmniAuth)

Suppose user can login using either Facebook Account or OpenId. If user uses Facebook, I would like to put a button like publish on my homepage, else I will not put anything on it. How do I tell which authentication method user is using in OmniAuth?
In your callback method, you can access the request.env["omniauth.auth"]["provider"] varaible to determine if he used Facebook vs. OpenID.

Resources