I'm trying to authenticate users with Omniauth, Devise and Ember.js. The problem is when it's signing the user, I'm redirected to http://localhost:3000/, and the session is never created, so ember doesn't receive anything.
I'm pretty sure my OmniauthCallbacksController is missing something, but I can't figure out what. I've followed the Omniauth tutorial, which is for Rails app I think, and not for Ember.
Here's my OmniauthCallbacksController:
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
respond_to :json
def google_oauth2
respond_to do |format|
format.json do
user = User.find_for_google_oauth2(request.env["omniauth.auth"], current_user)
if user.persisted?
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Google"
sign_in_and_redirect user, :event => :authentication
else
session["devise.google_data"] = request.env["omniauth.auth"]
redirect_to new_user_registration_url
end
end
end
end
end
And the console logs:
Processing by Users::OmniauthCallbacksController#google_oauth2 as JSON
Parameters: {"code"=>"4/PCzVgPNiiWBaypC-ClkI138x6TH-FSFwZ_bsQaH729E"}
Can't verify CSRF token authenticity
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."uid" = ? ORDER BY "users"."id" ASC LIMIT 1 [["uid", "105536114882368251887"]]
(0.1ms) begin transaction
SQL (0.5ms) UPDATE "users" SET "last_sign_in_at" = ?, "current_sign_in_at" = ?, "sign_in_count" = ?, "updated_at" = ? WHERE "users"."id" = ? [["last_sign_in_at", "2016-04-21 06:23:39.436817"], ["current_sign_in_at", "2016-04-21 07:12:29.715414"], ["sign_in_count", 6], ["updated_at", "2016-04-21 07:12:29.716294"], ["id", 1]]
(1.5ms) commit transaction
Redirected to http://localhost:3000/
Completed 302 Found in 32ms (ActiveRecord: 2.6ms)
Started GET "/" for ::1 at 2016-04-21 16:12:29 +0900
Processing by Rails::WelcomeController#index as HTML
Rendered /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.6/lib/rails/templates/rails/welcome/index.html.erb (1.7ms)
Completed 200 OK in 26ms (Views: 25.5ms | ActiveRecord: 0.0ms)
Aucun commentaire:
Enregistrer un commentaire