devise_token_authとomniauth-twitterを使って、twitterで認証しログインできるようにしたいです。
設定はこのような感じです。
# config/initializers/omniauth.rb Rails.application.config.middleware.use OmniAuth::Builder do provider :twitter, ENV['TWITTER_KEY'], ENV['TWITTER_SECRET'] end
rails.application.routes.draw do mount_devise_token_auth_for 'User', at: 'auth' end
class User < ActiveRecord::Base devise :database_authenticatable, :recoverable, :trackable, :validatable, :registerable, :omniauthable include DeviseTokenAuth::Concerns::User end
http://lcoalhost:3000:/auth/twitter にGETすると、
OAuth::Unauthorized 403 Forbiddenというエラーが出ます。
Started GET "/auth/twitter" for 127.0.0.1 at 2018-05-25 18:44:52 +0900 Started GET "/omniauth/twitter?resource_class=User" for 127.0.0.1 at 2018-05-25 18:44:52 +0900 I, [2018-05-25T18:44:52.686590 #23277] INFO -- omniauth: (twitter) Request phase initiated. OAuth::Unauthorized (403 Forbidden): oauth (0.5.4) lib/oauth/consumer.rb:236:in `token_request' oauth (0.5.4) lib/oauth/consumer.rb:155:in `get_request_token' omniauth-oauth (1.1.0) lib/omniauth/strategies/oauth.rb:28:in `request_phase' omniauth-twitter (1.4.0) lib/omniauth/strategies/twitter.rb:61:in `request_phase' omniauth (1.8.1) lib/omniauth/strategy.rb:224:in `request_call' omniauth (1.8.1) lib/omniauth/strategy.rb:187:in `call!' omniauth (1.8.1) lib/omniauth/strategy.rb:168:in `call' omniauth (1.8.1) lib/omniauth/builder.rb:63:in `call' rack (2.0.5) lib/rack/method_override.rb:22:in `call' rack (2.0.5) lib/rack/session/abstract/id.rb:232:in `context' rack (2.0.5) lib/rack/session/abstract/id.rb:226:in `call' actionpack (5.1.6) lib/action_dispatch/middleware/cookies.rb:613:in `call' warden (1.2.7) lib/warden/manager.rb:36:in `block in call' warden (1.2.7) lib/warden/manager.rb:35:in `catch' warden (1.2.7) lib/warden/manager.rb:35:in `call' rack (2.0.5) lib/rack/etag.rb:25:in `call' rack (2.0.5) lib/rack/conditional_get.rb:25:in `call' rack (2.0.5) lib/rack/head.rb:12:in `call' rack (2.0.5) lib/rack/session/abstract/id.rb:232:in `context' rack (2.0.5) lib/rack/session/abstract/id.rb:226:in `call' actionpack (5.1.6) lib/action_dispatch/middleware/cookies.rb:613:in `call' activerecord (5.1.6) lib/active_record/migration.rb:556:in `call' actionpack (5.1.6) lib/action_dispatch/middleware/callbacks.rb:26:in `block in call' activesupport (5.1.6) lib/active_support/callbacks.rb:97:in `run_callbacks' actionpack (5.1.6) lib/action_dispatch/middleware/callbacks.rb:24:in `call' actionpack (5.1.6) lib/action_dispatch/middleware/executor.rb:12:in `call' actionpack (5.1.6) lib/action_dispatch/middleware/debug_exceptions.rb:59:in `call' web-console (3.6.2) lib/web_console/middleware.rb:135:in `call_app' web-console (3.6.2) lib/web_console/middleware.rb:30:in `block in call' web-console (3.6.2) lib/web_console/middleware.rb:20:in `catch' web-console (3.6.2) lib/web_console/middleware.rb:20:in `call' actionpack (5.1.6) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call' railties (5.1.6) lib/rails/rack/logger.rb:36:in `call_app' railties (5.1.6) lib/rails/rack/logger.rb:24:in `block in call' activesupport (5.1.6) lib/active_support/tagged_logging.rb:69:in `block in tagged' activesupport (5.1.6) lib/active_support/tagged_logging.rb:26:in `tagged' activesupport (5.1.6) lib/active_support/tagged_logging.rb:69:in `tagged' railties (5.1.6) lib/rails/rack/logger.rb:24:in `call' actionpack (5.1.6) lib/action_dispatch/middleware/remote_ip.rb:79:in `call' actionpack (5.1.6) lib/action_dispatch/middleware/request_id.rb:25:in `call' rack (2.0.5) lib/rack/method_override.rb:22:in `call' rack (2.0.5) lib/rack/runtime.rb:22:in `call' activesupport (5.1.6) lib/active_support/cache/strategy/local_cache_middleware.rb:27:in `call' actionpack (5.1.6) lib/action_dispatch/middleware/executor.rb:12:in `call' actionpack (5.1.6) lib/action_dispatch/middleware/static.rb:125:in `call' rack (2.0.5) lib/rack/sendfile.rb:111:in `call' rack-cors (1.0.2) lib/rack/cors.rb:97:in `call' webpacker (3.5.3) lib/webpacker/dev_server_proxy.rb:22:in `perform_request' rack-proxy (0.6.4) lib/rack/proxy.rb:57:in `call' railties (5.1.6) lib/rails/engine.rb:522:in `call' puma (3.11.4) lib/puma/configuration.rb:225:in `call' puma (3.11.4) lib/puma/server.rb:632:in `handle_request' puma (3.11.4) lib/puma/server.rb:446:in `process_client' puma (3.11.4) lib/puma/server.rb:306:in `block in run' puma (3.11.4) lib/puma/thread_pool.rb:120:in `block in spawn_thread'
このエラーを解決したいです。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。