我在Heroku上託管了一個Rails應用程序,該應用程序通過使用代理服務來限制訪問。外部服務器充當所有請求的中介並處理用戶身份驗證。一旦用戶進行了認證,服務器(我認爲是LDAP)會將用戶名添加到請求標頭並將其重定向到我的應用程序。關於HTTP身份驗證方案的建議(使用請求標頭)
我想使用請求頭中的用戶名來驗證我的應用中的用戶。基本上,如果用戶不存在,我會創建一個用戶使用該用戶名(不需要密碼),如果不是,我只需登錄他們。我將存儲在我的應用程序的數據庫中的用戶。
我該怎麼做?爲此可以使用Devise嗎?
編輯:我得到了它與設計這樣的/自定義的監獄長戰略合作:
# config/initializers/my_strategy.rb
Warden::Strategies.add(:my_strategy) do
def valid?
true
end
def authenticate!
if !request.headers["my_key"]
fail!("You are not authorized to view this site.")
redirect!("proxy_url")
else
username = request.headers["my_key"]
user = User.find_by_username(username)
if user.nil?
user = User.create(:username => username)
end
success!(user)
end
end
end
#config/initializers/devise.rb
config.warden do |manager|
manager.default_strategies(:scope => :user).unshift :my_strategy
end
我需要作出這個作爲防彈越好。我是否還可以採取其他安全措施來確保某人無法欺騙請求標題並訪問我的網站?
我使用Rails 4做了與上面相同的事情。但是我在devsie方法user_signed_in中收到錯誤Invalid strategy ldap_authenticable_custom ?在我看來。有任何想法嗎? – 2016-08-24 03:36:48
@HP你解決了這個問題嗎? – 2017-02-16 10:18:25