# Gemfile
gem 'omniauth'
gem 'omniauth-google-oauth2'
gem 'devise'
# view
- if user_signed_in?
Signed in as
= current_user.oauth_name
= button_to('Sign out', destroy_user_session_path, method: :delete)
- else
= link_to('Sign in with Google', user_omniauth_authorize_path(:google_oauth2))
当用户被重定向到谷歌进行身份验证时,最好的方法是什么?
可能是“javascript onclick”,但我想以某种方式抓住服务器上的那一刻(如果可能的话),因为我需要将一些变量保存到会话中。
答案 0 :(得分:1)
有一个可以使用的init callbacks列表。我想你需要OmniAuth.config.before_request_phase
#config/initializers/omniauth.rb
OmniAuth.config.before_request_phase do |env|
env['omniauth.auth']
# Your code there
end