omniauthのTwitterプロバイダーのauthキーをコントローラーで設定
解決
遷移するパスが正しくなかった。(/api/auth/:provider/setup
の様にscopeをネストしていた)
デフォルトで遷移する /auth/:provider/setup
以外になる場合は、 setup_path
を設定する必要がある。
scopeをネスト指定していなければ、 setup: true
だけでOK
Rails.application.config.middleware.use OmniAuth::Builder do
provider :twitter,
setup: true,
setup_path: "/path/to/auth/twitter/setup",
callback_path: "/path/to/auth/twitter/callback",
image_size: "original"
...
scope :auth do
...
get '/:provider/setup', to: "auth#setup", as: :auth_setup
...
end
...
class SessionsController < ApplicationController
def setup
# in this example facebook keys for different site domains are stored in Config
request.env['omniauth.strategy'].options[:client_id] = Config[domain]['appKey']
request.env['omniauth.strategy'].options[:client_secret] = Config[domain]['appSecret']
render json: { message: "Omniauth setup phase." }, :status => 404
end
end
事象
Setup Phase · omniauth/omniauth Wiki · GitHub 通りに、omniauth.strategyの値を動的に設定する設定をしたのだが、指定したコントローラーの処理を実行してくれない。
ログには omniauth: (twitter) Calling through to underlying application for setup.
が出力されている