Refresh token using Omniauth-oauth2 in Rails application

Omniauth doesn’t offer this functionality out of the box so i used the previous answer and another SO answer to write the code in my model User.rb def refresh_token_if_expired if token_expired? response = RestClient.post “#{ENV[‘DOMAIN’]}oauth2/token”, :grant_type => ‘refresh_token’, :refresh_token => self.refresh_token, :client_id => ENV[‘APP_ID’], :client_secret => ENV[‘APP_SECRET’] refreshhash = JSON.parse(response.body) token_will_change! expiresat_will_change! self.token = refreshhash[‘access_token’] … Read more

Omniauth Facebook Error – Faraday::Error::ConnectionFailed

I’ve fixed this on Mac OS X Lion 10.7.4 with this solution: $ rvm remove 1.9.3 (or whatever version of ruby you are using) $ rvm pkg install openssl $ rvm install 1.9.3 –with-openssl-dir=$rvm_path/usr after this you will need to download the missing cacert.pem file: $ cd $rvm_path/usr/ssl $ sudo curl -O http://curl.haxx.se/ca/cacert.pem $ sudo … Read more

Setting Environment Variables in Rails 3 (Devise + Omniauth)

You could take a look at the comments: You can either set environment variables directly on the shell where you are starting your server: FACEBOOK_APP_ID=12345 FACEBOOK_SECRET=abcdef rails server Or (rather hacky), you could set them in your config/environments/development.rb: ENV[‘FACEBOOK_APP_ID’] = “12345”; ENV[‘FACEBOOK_SECRET’] = “abcdef”; An alternative way However I would do neither. I would create … Read more

Authenticate user using omniauth and Facebook for a rails API?

the best way I found (after being stuck for a while on this issue ) is to do your omniauth2 (specifically in my case using satellizer angular plugin) manually… I’ll discuss the solution for Facebook as it was my case, but everything could apply to any other provider. first you have to know how omniauth2 … Read more

Passing parameters through OmniAuth

After struggling with all the above answers, I figured out what to do regarding Facebook, which by default does not display the params in request.env[“omniauth.auth”]. So — If you are using a query string for the callback, similar to something like this: “/auth/facebook?website_id=#{@website.id}” The only way to get that website_id param is by using request.env[“omniauth.params”]. … Read more

Turn omniauth facebook login into a popup

Sure, you can easily. In your view: =link_to “Log in with Facebook”, omniauth_authorize_path(:user, :facebook), :class => “popup”, :”data-width” => 600, :”data-height” => 400 In your application.js: function popupCenter(url, width, height, name) { var left = (screen.width/2)-(width/2); var top = (screen.height/2)-(height/2); return window.open(url, name, “menubar=no,toolbar=no,status=no,width=”+width+”,height=”+height+”,toolbar=no,left=”+left+”,top=”+top); } $(“a.popup”).click(function(e) { popupCenter($(this).attr(“href”), $(this).attr(“data-width”), $(this).attr(“data-height”), “authPopup”); e.stopPropagation(); return false; }); … Read more

OmniAuth & Facebook: certificate verify failed [duplicate]

The real problem is that Faraday (which Omniauth/Oauth use for their HTTP calls) is not wasn’t setting the ca_path variable for OpenSSL. At least on Ubuntu, most root certs are stored in “/etc/ssl/certs”. Since Faraday isn’t wasn’t setting this variable (and currently does not have a method to do so), OpenSSL isn’t wasn’t finding the … Read more