0
我有一個使用omniauth-google-oauth2
gem的rails 4.2.7應用程序設置,我想從auth哈希中檢索first_name
和last_name
。使用omniauth-google-oauth2從auth哈希中檢索first_name和last_name gem
我能夠與omniauth-facebook
寶石通過修改devise.rb
看起來像下面這樣做,
devise.rb
# Omniauth/Oauth2 settings
callback_url = if Rails.env == "development"
ENV['FB_CALLBACK']
else
ENV['FB_CALLBACK_PROD']
end
config.omniauth :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET'], callback_url: callback_url,
:scope => 'email',
:info_fields => 'email, first_name, last_name'
# Google - OmniAuth
require 'omniauth-google-oauth2'
config.omniauth :google_oauth2, ENV["GOOGLE_CLIENT_ID"], ENV["GOOGLE_CLIENT_SECRET"]
不過,我似乎無法弄清楚如何使用omniauth-google-oauth2
檢索first_name/last_name。任何幫助將不勝感激。
您所展示的只是配置。現在,當你調用'User.from_omniauth(request.env [「omniauth.auth」]'方法「時,[https://github.com/zquestz/omniauth-google-oauth2#devise]提供了響應。 –