http://www.theodinproject.com/ruby-on-rails/final-projectの Facebook クローン プロジェクトに取り組んでいます。
私は omniauth-facebook 部分で立ち往生しており、facebook で正常にログインできません。問題は request.env["omniauth.auth"] が原因である可能性があると思います。request.env["omniauth.auth"].to_yaml を上げようとすると。次の不完全なハッシュを取得します。first_name、last_name、gender などの多くの情報が欠落しています。
--- !ruby/hash:OmniAuth::AuthHash
provider: facebook
uid: '10206926404981253'
info: !ruby/hash:OmniAuth::AuthHash::InfoHash
name: Thomas Pan
image: http://graph.facebook.com/10206926404981253/picture
credentials: !ruby/hash:OmniAuth::AuthHash
token: <token>
expires_at: 1442277104
expires: true
extra: !ruby/hash:OmniAuth::AuthHash
raw_info: !ruby/hash:OmniAuth::AuthHash
name: Thomas Pan
id: <id>
** セキュリティのために一部の情報を <> に置き換えました。
これもdeviseと一緒に使っています。
ここのdeviseとomniauth-facebookの指示に従っているので、他のすべては正しく設定されているようです。https://github.com/plataformatec/devise/wiki/OmniAuth:-概要
user.rb
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:omniauthable, :omniauth_providers => [:facebook]
def self.from_omniauth(auth)
where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
user.email = auth.info.email
user.password = Devise.friendly_token[0,20]
user.first_name = auth.info.first_name
user.last_name = auth.info.last_name
user.gender = auth.extra.raw.gender
end
end
devise.rb
config.omniauth :facebook, ENV['FB_APP_ID'], ENV['FB_APP_SECRET']
ルート.rb
devise_for :users, :controllers => { :registrations => "users/registrations", :omniauth_callbacks => "users/omniauth-callbacks" }
omniauth_callbacks_controller.rb
def facebook
raise request.env['omniauth.auth'].to_yaml
end
end
どんな援助でも大歓迎です!
バージョン情報: Rails 4.2.1 Ruby 2.0.0