1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Doorkeeper 5.1.0 + Sorcery 0.13.0 + Rails APIで認証に失敗する問題

Last updated at Posted at 2019-04-25

事象

Doorkeeperを5.1.0に上げると、APIで認証した際に、以下のエラーが出るようになった。

NameError (undefined local variable or method `cookies' for #<Doorkeeper::TokensController:0x00007ffeb6604b10>):

対応

以下のパッチをあてる。

module Doorkeeper
  module ApplicationMetalControllerPatch
    def current_user; end
  end
end

Rails.application.config.to_prepare do
  Doorkeeper::ApplicationMetalController.prepend Doorkeeper::ApplicationMetalControllerPatch
end

原因

  • Doorkeeper 5.1.0からDoorkeeper::ApplicationMetalControllerActionController::APIを継承するように変更された
  • sorcery 0.13.0からActionController::APIにもsorcery関連の処理が追加されるようになった

原因から影響を受けた挙動

  • Doorkeeper::TokensControllerrender jsonする
  • ActiveModelSerializerのserialization_scopeでデフォルト値のcurrent_userが呼ばれる
  • sorceryのcurrent_userが呼び出され、運悪くremember_meのモジュールとか入れていると、APIなのにcookieを読み込もうとする...
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?