2

我使用不同的流程与门卫玩耍。我尝试使用密码流、客户端凭据流成功,但使用授权代码流时出现以下错误:

NoMethodError in Doorkeeper::AuthorizationsController#new

undefined method `id' for nil:NilClass

当我单击授权按钮时,如下所示:点击授权按钮

错误页面:

在此处输入图像描述

请帮忙

4

2 回答 2

2

最后它对我有用。问题是因为我确实有 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
于 2014-10-20T01:55:54.820 回答
2

在我意识到您必须从 resource_owner_authenticator 块返回用户之前,我遇到了同样的错误(这在文档中并不明显)。我在块中的最后一行没有返回用户,这引发了错误。

于 2015-07-28T02:25:48.897 回答