#質問したいこと
ruby on railsにてtwitter認証処理を実装しているのですが、ユーザー側がキャンセルした際にエラーが発生しまいます。
キャンセル時の対処方法がわからず、誰か知っている方いましたら、ご教授お願いします。
ユーザー側が認証した場合は正常に動作することは確認しています。
#実行環境
Rails 5.2.2
ruby 2.4.1p111
oauth (0.5.4)
omniauth (1.9.0)
omniauth-oauth (1.1.0)
omniauth-twitter (1.4.0)
#エラーコード
Started GET "/auth/twitter" for 127.0.0.1 at 2019-03-26 11:09:23 +0900
Started GET "/auth/twitter" for 127.0.0.1 at 2019-03-26 11:09:24 +0900
Started GET "/auth/twitter/callback?denied=VGg0kgAAAAAA9nd5AAABabfCZc4" for 127.0.0.1 at 2019-03-26 11:09:32 +0900
OAuth::Unauthorized (401 Authorization Required):
vendor/bundle/gems/oauth-0.5.4/lib/oauth/consumer.rb:236:in token_request' vendor/bundle/gems/oauth-0.5.4/lib/oauth/tokens/request_token.rb:20:in
get_access_token'
vendor/bundle/gems/omniauth-oauth-1.1.0/lib/omniauth/strategies/oauth.rb:56:in callback_phase' vendor/bundle/gems/omniauth-1.9.0/lib/omniauth/strategy.rb:238:in
callback_call'
vendor/bundle/gems/omniauth-1.9.0/lib/omniauth/strategy.rb:189:in call!' vendor/bundle/gems/omniauth-1.9.0/lib/omniauth/strategy.rb:169:in
call'
vendor/bundle/gems/omniauth-1.9.0/lib/omniauth/builder.rb:64:in call' vendor/bundle/gems/rack-2.0.6/lib/rack/tempfile_reaper.rb:15:in
call'
vendor/bundle/gems/rack-2.0.6/lib/rack/etag.rb:25:in call' vendor/bundle/gems/rack-2.0.6/lib/rack/conditional_get.rb:25:in
call'
vendor/bundle/gems/rack-2.0.6/lib/rack/head.rb:12:in call' vendor/bundle/gems/actionpack-5.2.2/lib/action_dispatch/http/content_security_policy.rb:18:in
call'
vendor/bundle/gems/rack-2.0.6/lib/rack/session/abstract/id.rb:232:in context' vendor/bundle/gems/rack-2.0.6/lib/rack/session/abstract/id.rb:226:in
call'
vendor/bundle/gems/actionpack-5.2.2/lib/action_dispatch/middleware/cookies.rb:670:in call' vendor/bundle/gems/activerecord-5.2.2/lib/active_record/migration.rb:559:in
call'
vendor/bundle/gems/actionpack-5.2.2/lib/action_dispatch/middleware/callbacks.rb:28:in block in call' vendor/bundle/gems/activesupport-5.2.2/lib/active_support/callbacks.rb:98:in
run_callbacks'
vendor/bundle/gems/actionpack-5.2.2/lib/action_dispatch/middleware/callbacks.rb:26:in call' vendor/bundle/gems/actionpack-5.2.2/lib/action_dispatch/middleware/executor.rb:14:in
call'
vendor/bundle/gems/actionpack-5.2.2/lib/action_dispatch/middleware/debug_exceptions.rb:61:in call' vendor/bundle/gems/web-console-3.7.0/lib/web_console/middleware.rb:135:in
call_app'
vendor/bundle/gems/web-console-3.7.0/lib/web_console/middleware.rb:30:in block in call' vendor/bundle/gems/web-console-3.7.0/lib/web_console/middleware.rb:20:in
catch'
vendor/bundle/gems/web-console-3.7.0/lib/web_console/middleware.rb:20:in call' vendor/bundle/gems/actionpack-5.2.2/lib/action_dispatch/middleware/show_exceptions.rb:33:in
call'
vendor/bundle/gems/railties-5.2.2/lib/rails/rack/logger.rb:38:in call_app' vendor/bundle/gems/railties-5.2.2/lib/rails/rack/logger.rb:26:in
block in call'
vendor/bundle/gems/activesupport-5.2.2/lib/active_support/tagged_logging.rb:71:in block in tagged' vendor/bundle/gems/activesupport-5.2.2/lib/active_support/tagged_logging.rb:28:in
tagged'
vendor/bundle/gems/activesupport-5.2.2/lib/active_support/tagged_logging.rb:71:in tagged' vendor/bundle/gems/railties-5.2.2/lib/rails/rack/logger.rb:26:in
call'
vendor/bundle/gems/sprockets-rails-3.2.1/lib/sprockets/rails/quiet_assets.rb:13:in call' vendor/bundle/gems/actionpack-5.2.2/lib/action_dispatch/middleware/remote_ip.rb:81:in
call'
vendor/bundle/gems/actionpack-5.2.2/lib/action_dispatch/middleware/request_id.rb:27:in call' vendor/bundle/gems/rack-2.0.6/lib/rack/method_override.rb:22:in
call'
vendor/bundle/gems/rack-2.0.6/lib/rack/runtime.rb:22:in call' vendor/bundle/gems/activesupport-5.2.2/lib/active_support/cache/strategy/local_cache_middleware.rb:29:in
call'
vendor/bundle/gems/actionpack-5.2.2/lib/action_dispatch/middleware/executor.rb:14:in call' vendor/bundle/gems/actionpack-5.2.2/lib/action_dispatch/middleware/static.rb:127:in
call'
vendor/bundle/gems/rack-2.0.6/lib/rack/sendfile.rb:111:in call' vendor/bundle/gems/railties-5.2.2/lib/rails/engine.rb:524:in
call'
vendor/bundle/gems/puma-3.12.0/lib/puma/configuration.rb:225:in call' vendor/bundle/gems/puma-3.12.0/lib/puma/server.rb:658:in
handle_request'
vendor/bundle/gems/puma-3.12.0/lib/puma/server.rb:472:in process_client' vendor/bundle/gems/puma-3.12.0/lib/puma/server.rb:332:in
block in run'
vendor/bundle/gems/puma-3.12.0/lib/puma/thread_pool.rb:133:in `block in spawn_thread'
ruby
1 get 'auth/twitter' 2 get '/auth/:provider/callback', to: 'authentication_management#twitter_auth' 3 get '/logout', to: 'authentication_management#logout'
ruby
1 def twitter_auth 2 #以下で認証に関する処理を追加する。 3 #取得したデータが不正でなければ、ユーザー登録(users/twitter_new)を実施する 4 #現在は特になし 5 #ユーザー登録処理で使用するために、フラッシュにデータを設定する。 6 #そのまま渡すとデータサイズが大きすぎてエラーになるため、必要な分だけ渡す 7 auth_data = request.env['omniauth.auth'] 8 flash[:twitter_provider] = auth_data[:provider] 9 flash[:twitter_uid] = auth_data[:uid] 10 flash[:twitter_name] = auth_data[:info][:name] 11 redirect_to users_twitter_new_url 12 end
#試したこと
・エラーコードにStarted GET "/auth/twitter/callback?denied=VGg0kgAAAAAA9nd5AAABabfCZc4
となっていたので、ルート設定を以下のように設定した。
before: GET "/auth/twitter/callback'
after: GET "/auth/twitter/callback/:denied'
・別の人の記事にget '/logout', to: 'service#entrance_screen'と記載があったので、これがキャンセル時のpost先かなと判断して記述してみたがエラーになってしまった。
logoutをsignoutに変更して試してもみました。
・rails twitter認証キャンセル時でググってみましたが、該当の記事がありませんでした。
・コードで示したtwitter_authアクションが通っているか確認するため、logを残すようにしましたが、logは出力されず通った形跡はありませんでした。
・twitter認証apiのアプリ作成時の設定にて、キャンセル時のurl等を入力する場所があるか確認しましたが、特にそれらしいものを入力する場所はありませんでした。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/03/26 06:40
2019/03/26 07:09
2019/03/26 07:38
2019/03/26 08:00
2019/03/26 08:08
2019/03/26 08:29
2019/03/26 12:18
2019/03/26 12:36
2019/03/26 20:50
2019/03/27 03:16
2019/03/27 03:36
2019/03/27 04:17
2019/03/27 04:26
2019/03/27 05:13
2019/03/27 06:11
2019/03/27 07:36