我正在尝试在ruby on rails上实现我的第一个基于authlogic的应用程序。我需要使用自定义oauth2流程对用户进行签名,在流程结束时,我想告诉authlogic我希望他对哪个用户进行身份验证。不提供登录名或密码,只需直接传递用户对象。
我在自述文件中发现,我可以使用UserSession.create(user, true)
执行此操作,但在OAuth回调步骤结束时将其放在我的用户身上。没有错误也没有异常,一切似乎都很好,但UserSession.find
返回nil(即使在UserSession.create
之后的下一行)。我在rails 5.1.6和authlogic 4.0.1上。
用户模型
class User < ApplicationRecord
acts_as_authentic
end
UserSession模型
class UserSession < Authlogic::Session::Base
end
提前感谢任何有关我做错的线索。
答案 0 :(得分:0)
module Authlogic
module Session # :nodoc:
# This is the most important class in Authlogic. You will inherit this class
# for your own eg. `UserSession`.
#
# Code is organized topically. Each topic is represented by a module. So, to
# learn about password-based authentication, read the `Password` module.
#
# It is common for methods (.initialize and #credentials=, for example) to
# be implemented in multiple mixins. Those methods will call `super`, so the
# order of `include`s here is important.
#
# Also, to fully understand such a method (like #credentials=) you will need
# to mentally combine all of its definitions. This is perhaps the primary
# disadvantage of topical organization using modules.
当我从他们的指示中读到时,他们绝不会说您可以在没有电子邮件和密码的情况下对用户进行身份验证,但是您可以使用User
对象创建会话
# skip authentication and log the user in directly, the true means "remember me"
UserSession.create(my_user_object, true)
我会详细了解Session.rb
https://github.com/binarylogic/authlogic/blob/master/lib/authlogic/session/session.rb
对不起,如果我不能给你更多的帮助
PS你也可以通过在gem文件中设置binding.pry来调试这个gem