##deviseでfacebookユーザー認証がうまく機能していない
導入したはじめは,facebookで登録するのボタンを押してみると、ちゃんとfacebookAPI側のページ切り変わって、ごの名前で続けますか?みたいなところまでは表示されました。
問題はそのあとなのですが、それ以降ボタンを押しても、なんの反応もしなくなりました。まして、databaseの中を確認してもユーザーが追加されているわけでもありませんでした。
gitのチュートリアルをみて進めました。
サーバーの反応
Started GET "/users/sign_up" for 127.0.0.1 at 2017-05-18 10:18:13 +0900 Processing by Devise::RegistrationsController#new as HTML Rendering devise/registrations/new.html.erb within layouts/application Rendered partial/_navbar.html.erb (1.6ms) [cache miss] Rendered partial/_deviseErrorMsg.html.erb (1.3ms) [cache miss] Rendered devise/shared/_links.html.erb (1.4ms) [cache miss] Rendered devise/registrations/new.html.erb within layouts/application (35.9ms) Completed 200 OK in 92ms (Views: 91.0ms | ActiveRecord: 0.0ms) Started GET "/users/auth/facebook" for 127.0.0.1 at 2017-05-18 10:18:14 +0900 I, [2017-05-18T10:18:14.217859 #54438] INFO -- omniauth: (facebook) Request phase initiated. Started GET "/users/auth/facebook" for 127.0.0.1 at 2017-05-18 10:18:14 +0900 I, [2017-05-18T10:18:14.719085 #54438] INFO -- omniauth: (facebook) Request phase initiated. Started GET "/users/auth/facebook/callback?code=AQBgPbgvBmdBdpXERIXf-GYr9ZQXAQzrSx7xvz2NNk1GFKzzC0-lYY-vgn8ibzoR6gfflCvvnIIevyfk5RHp5C0FVW2U_ub1B3CQjribETL_vCerVBJVUy7VnbcGpbBM2Ucik8ZzWC2z0E8DwJZ6J4qrPl51eMNeoZb6fA-937twgZkbZ6uNnrfPVfVGudDebdojDareiTrkh5i_dXdz29JmTZ4J5PM7MctcuITXUdvShQp3aZoMmhN8uAjP8nSu4FSuT-_2xTo_OtutVHG-GuRLH8xggp30OgKovp-ZRsVFieK9_SyN4aC6E3vWeAUMigiHEdjqeWGRJpb9v2R7Xt2_&state=d801e6f1ad665c35b4e409138f2a31ec46e49e9961be8114" for 127.0.0.1 at 2017-05-18 10:18:14 +0900 I, [2017-05-18T10:18:14.916662 #54438] INFO -- omniauth: (facebook) Callback phase initiated. Processing by Users::OmniauthCallbacksController#facebook as HTML Parameters: {"code"=>"AQBgPbgvBmdBdpXERIXf-GYr9ZQXAQzrSx7xvz2NNk1GFKzzC0-lYY-vgn8ibzoR6gfflCvvnIIevyfk5RHp5C0FVW2U_ub1B3CQjribETL_vCerVBJVUy7VnbcGpbBM2Ucik8ZzWC2z0E8DwJZ6J4qrPl51eMNeoZb6fA-937twgZkbZ6uNnrfPVfVGudDebdojDareiTrkh5i_dXdz29JmTZ4J5PM7MctcuITXUdvShQp3aZoMmhN8uAjP8nSu4FSuT-_2xTo_OtutVHG-GuRLH8xggp30OgKovp-ZRsVFieK9_SyN4aC6E3vWeAUMigiHEdjqeWGRJpb9v2R7Xt2_", "state"=>"d801e6f1ad665c35b4e409138f2a31ec46e49e9961be8114"} User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."provider" = ? AND "users"."uid" = ? ORDER BY "users"."id" ASC LIMIT ? [["provider", "facebook"], ["uid", "1777251139255645"], ["LIMIT", 1]] (0.1ms) begin transaction User Exists (0.6ms) SELECT 1 AS one FROM "users" WHERE "users"."email" = ? LIMIT ? [["email"], ["LIMIT", 1]] (0.1ms) rollback transaction Redirected to http://localhost:3000/users/sign_up Completed 302 Found in 184ms (ActiveRecord: 1.1ms)
コントローラーの内容
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController def facebook # You need to implement the method below in your model (e.g. app/models/user.rb) @user = User.from_omniauth(request.env["omniauth.auth"]) if @user.persisted? sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format? else session["devise.facebook_data"] = request.env["omniauth.auth"] redirect_to new_user_registration_url end end def failure redirect_to root_path end end end
##設定一覧
gem
gem 'rails', '~> 5.1.0' gem 'sqlite3' gem 'puma', '~> 3.7' gem 'sass-rails', '~> 5.0' gem 'uglifier', '>= 1.3.0' gem 'coffee-rails', '~> 4.2' gem 'turbolinks', '~> 5' gem 'jbuilder', '~> 2.5' gem 'bootstrap-sass' gem 'autoprefixer-rails' gem 'devise' gem 'jquery-rails' gem 'jquery-ui-rails' gem 'toastr-rails' gem 'omniauth-facebook' gem 'actionpack-page_caching'
devise.rb
# ==> OmniAuth # Add a new OmniAuth provider. Check the wiki for more information on setting # up on your models and hooks. # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo' # ==> Warden configuration # If you want to use other strategies, that are not supported by Devise, or # change the failure app, you can configure them inside the config.warden block. # # config.warden do |manager| # manager.intercept_401 = false # manager.default_strategies(scope: :user).unshift :some_external_strategy # end # ==> Mountable engine configurations # When using Devise inside an engine, let's call it `MyEngine`, and this engine # is mountable, there are some extra configurations to be taken into account. # The following options are available, assuming the engine is mounted as: # # mount MyEngine, at: '/my_engine' # # The router that invoked `devise_for`, in the example above, would be: # config.router_name = :my_engine # # When using OmniAuth, Devise cannot automatically set OmniAuth path, # so you need to do it manually. For the users scope, it would be: # config.omniauth_path_prefix = '/my_engine/users/auth' config.omniauth :facebook, "419987595054517", "ae3d9fae963284ede5abeec3b9784850", scope: 'email', info_fields: 'email,name' end
routes.rb
Rails.application.routes.draw do root :to => 'pages#index' devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" } # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html end
回答1件
あなたの回答
tips
プレビュー