Authlogic HTTP Basic UserSession.find 返回 nil,意味着 declarative_authorization 无法获取 current_user

发布于 2024-09-25 03:33:54 字数 539 浏览 5 评论 0原文

当使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

删除会话 2024-10-02 03:33:54

撞这个。我完全有同样的问题(使用相同的 gem - authlogic + declarative_auth)。

为我找到了解决方案,我所需要做的就是将以下代码复制到authorization_rules.rb的末尾

privileges do
  privilege :manage, :includes => [:create, :read, :update, :delete]
  privilege :read, :includes => [:index, :show]
  privilege :create, :includes => :new
  privilege :update, :includes => :edit
  privilege :delete, :includes => :destroy
end

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

privileges do
  privilege :manage, :includes => [:create, :read, :update, :delete]
  privilege :read, :includes => [:index, :show]
  privilege :create, :includes => :new
  privilege :update, :includes => :edit
  privilege :delete, :includes => :destroy
end
皓月长歌 2024-10-02 03:33:54

摆弄了 Devise,现在一切似乎都正常工作,只要使用 ActiveResource 时我做 site =“http://user:password@domain”,而不是:

site = "http://domain"
username = "user"
password = "password"

哪个不起作用。我还没有花时间去探究原因。

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:

site = "http://domain"
username = "user"
password = "password"

Which doesn't work. I havn't taken the time to dig into why.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文