我使用不同的流程与门卫玩耍。我尝试使用密码流、客户端凭据流成功,但使用授权代码流时出现以下错误:
NoMethodError in Doorkeeper::AuthorizationsController#new
undefined method `id' for nil:NilClass
当我单击授权按钮时,如下所示:
错误页面:
请帮忙
我使用不同的流程与门卫玩耍。我尝试使用密码流、客户端凭据流成功,但使用授权代码流时出现以下错误:
NoMethodError in Doorkeeper::AuthorizationsController#new
undefined method `id' for nil:NilClass
当我单击授权按钮时,如下所示:
错误页面:
请帮忙
最后它对我有用。问题是因为我确实有 resource_owner_authenticator 块来返回 config/initializers/doorkeeper.rb 中的用户对象。
#config/initializers/doorkeeper.rb
resource_owner_authenticator do
User.find_by(id: session[:user_id]) || redirect_to(login_url)
end
resource_owner_from_credentials do |routes|
User.authenticate(params[:username], params[:password])
end
在我意识到您必须从 resource_owner_authenticator 块返回用户之前,我遇到了同样的错误(这在文档中并不明显)。我在块中的最后一行没有返回用户,这引发了错误。