Authlogic HTTP Basic UserSession.find 返回 nil,意味着 declarative_authorization 无法获取 current_user
当使用 Authlogic 的 HTTP Basic auth 时,UserSession.find 返回 nil,因为会话似乎未设置。因此,引用通常的 current_user 方法(如下)的 declarative_authorization 无法找到当前用户。
def current_user_session
return @current_user_session if defined?(@current_user_session)
@current_user_session = UserSession.find
end
def current_user
return @current_user if defined?(@current_user)
@current_user = current_user_session && current_user_session.record
end
当用户通过 HTTP basic 进行身份验证时是否可以创建会话(即使该会话只会持续到请求关闭为止),或者是否有更好的方法来执行此操作?
When using Authlogic's HTTP Basic auth, UserSession.find returns nil since the session appears not to be set. As a result, declarative_authorization, which references the usual current_user method (as below), can't find a current user.
def current_user_session
return @current_user_session if defined?(@current_user_session)
@current_user_session = UserSession.find
end
def current_user
return @current_user if defined?(@current_user)
@current_user = current_user_session && current_user_session.record
end
Is it possible to create a session when a user auths via HTTP basic (even though that session will only last until the request closes) or is there a better way of doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
撞这个。我完全有同样的问题(使用相同的 gem - authlogic + declarative_auth)。
为我找到了解决方案,我所需要做的就是将以下代码复制到authorization_rules.rb的末尾
Bumping this. I'm exactly having the same issue (with the same gems - authlogic + declarative_auth).
Found the solution for me, all i needed was to copy the following code to the end of the authorization_rules.rb
摆弄了 Devise,现在一切似乎都正常工作,只要使用 ActiveResource 时我做 site =“http://user:password@domain”,而不是:
哪个不起作用。我还没有花时间去探究原因。
Having fiddled with Devise, everything now seems to be working, as long as when using ActiveResource I do site = "http://user:password@domain", rather than:
Which doesn't work. I havn't taken the time to dig into why.