我想使用idenity provider为我的应用程序使用单独的管理员登录。
我在config / initializers / omniauth.rb
中写了这个Rails.application.config.middleware.use OmniAuth::Builder do
provider :identity, :model => Credential, :on_failed_registration =>SessionsController.action(:register)
provider :identity, :model => Credential, :name => 'admin', :on_failed_registration => SessionsController.action(:login_admin)
provider :google_oauth2, '000000000.apps.googleusercontent.com', '00000000000'
end
在config / routes.rb
中 match '/auth/admin/callback', :to => 'sessions#authenticate_admin'
在app / controllers / sessions_controller.rb
中def authenticate_admin
auth_hash = request.env['omniauth.auth']
session[:admin_user] = auth_hash['user_info']['email']
if admin?
redirect_to '/'
else
render :text => '401 Unauthorized', :status => 401
end
end
但是当我尝试访问request.env ['omniauth.auth']时,它总是为零。虽然在sessison #create action中为普通用户使用默认回调时可以访问它。我只是想知道这段代码中是否有任何遗漏。我正在关注此博客http://www.intridea.com/blog/2011/1/31/easy-rails-admin-login-with-google-apps-and-omniauth。