Update
If you are using omniauth-facebook
please follow deivid's answer.
Another way to solve this issue is to replace http with https. In that way it will redirect from https to https and you won't get a redirection forbidden error.
Example
> url = auth.info.image
=> "http://graph.facebook.com/672086173/picture?type=square"
> avatar_url =url.gsub("http","https")
=> "https://graph.facebook.com/672086173/picture?type=square"
I had the exact same problem. I solve it with following steps
First in your gemfile add
gem 'open_uri_redirections'
and run bundle install to install the gem
And then in your model
private
def process_uri(uri)
require 'open-uri'
require 'open_uri_redirections'
open(uri, :allow_redirections => :safe) do |r|
r.base_uri.to_s
end
end
Now process the avatar url with the method like
if auth.info.image.present?
avatar_url = process_uri(auth.info.image)
user.update_attribute(:avatar, URI.parse(avatar_url))
end
Hope this helps anyone else that may be having this issue.