Tôi đang gặp sự cố khi sử dụng OmniAuth với Rails 4.0.0.beta1 trong đó giá trị phiên được đặt trong SessionsController không được duy trì trên chuyển hướng. Tôi đang cố gắng tìm ra nếu nó là một cái gì đó trong mã của tôi, một lỗi trong Rails 4, hoặc một sự không tương thích với đá quý OmniAuth. Tôi đang sử dụng chiến lược nhà phát triển OmniAuth.Phiên không duy trì chuyển hướng chéo với OmniAuth và Rails 4
Tôi không chắc chắn nếu điều này có nghĩa là bất cứ điều gì, nhưng nếu tôi đặt một trình gỡ lỗi trong SessionsController#create
sau dòng session[:user_id] = user.id
và kiểm tra lớp đối tượng session, tôi nhận được:
ActionController::RequestForgeryProtection::ProtectionMethods::NullSession::NullSessionHash
Tuy nhiên, nếu tôi kiểm tra cùng lớp phiên trong một ứng dụng khác đang chạy Rails 3.2 Tôi nhận được:
Hash
Có lẽ OmniAuth không thể xử lý đối tượng NullSessionHash một cách thích hợp?
sessions_controller
class SessionsController < ApplicationController
skip_before_filter :authenticate_user!
def create
user = User.find_or_create_by_auth_hash(auth_hash)
session[:user_id] = user.id
redirect_to root_path
end
protected
def auth_hash
request.env['omniauth.auth']
end
end
config/initializers/secret_token.rb
MyApp::Application.config.secret_key_base = 'REMOVED'
config/initializers/session_store.rb
MyApp::Application.config.session_store :encrypted_cookie_store, key: '_my_app_session'
Cảm ơn bạn rất nhiều! –