I'm using Noam Ben Ari's awesome gem Sorcery, and there is an issue I can't figure out.
Facebook login works fine on local server, but not on Heroku:
2011-10-03T03:50:21+00:00 app[web.1]: Started GET "/oauth/callback? provider=facebook&code=AQAJ-kjae6XnC-4R82G3DlaYseLxKFK09t9EN5Cwk-MuoctkE1iiY- tKVGM1n9YkUjhyjmhZptdOkxyytFWgFHB2RlihH1S3FdsysmKLlw7UztqczyLys_plQIRdF7YzRUi0dGqynn9j9rkqHNK7 KWqswT62usruyumS0m0d4LRCauCnPQ-SPtrNrFRdeWe0Aww" for 154.5.97.249 at 2011-10-03 03:50:21 +0开发者_JS百科000
2011-10-03T03:50:21+00:00 app[web.1]: Processing by OauthsController#callback as HTML
2011-10-03T03:50:21+00:00 app[web.1]: Parameters: {"provider"=>"facebook", "code"=>"AQAJ-kjae6XnC-4R82G3DlaYseLxKFK09t9EN5Cwk-MuoctkE1iiY- tKVGM1n9YkUjhyjmhZptdOkxyytFWgFHB2RlihH1S3FdsysmKLlw7UztqczyLys_plQIRdF7YzRUi0dGqynn9j9rkqHNK7 KWqswT62usruyumS0m0d4LRCauCnPQ-SPtrNrFRdeWe0Aww"}
2011-10-03T03:50:21+00:00 app[web.1]: Completed 500 Internal Server Error in 841ms
0-03T03:50:21+00:00 app[web.1]:
2011-10-03T03:50:21+00:00 app[web.1]: NoMethodError (undefined method 'load_from_provider' for #<Class:0x00000003fd4190>):
2011-10-03T03:50:21+00:00 app[web.1]: app/controllers/oauths_controller.rb:12:in 'callback'
2011-10-03T03:50:21+00:00 app[web.1]:
2011-10-03T03:50:21+00:00 app[web.1]:
2011-10-03T03:50:21+00:00 app[web.1]: cache: [GET /oauth/callback?provider=facebook&code=AQAJ-kjae6XnC-4R82G3DlaYseLxKFK09t9EN5Cwk-MuoctkE1iiY-tKVGM1n9YkUjhyjmhZptdOkxyytFWgFHB2RlihH1S3FdsysmKLlw7UztqczyLys_plQIRdF7YzRUi0dGqynn9j9rkqHNK7KWqswT62usruyumS0m0d4LRCauCnPQ-SPtr
I'm using his own sample code on Rails 3.1.0, Sorcery 0.6.1.
Here is the culprit controller:
class OauthsController < ApplicationController
skip_before_filter :require_login
def oauth
login_at(params[:provider])
end
def callback
provider = params[:provider]
if @user = login_from(provider) # <<<< this is the faulty line #12
redirect_to root_path, :notice => "Logged in from #{provider.titleize}!"
else
begin
@user = create_from(provider)
reset_session # protect from session fixation attack
login_user(@user)
redirect_to root_path, :notice => "Logged in from #{provider.titleize}!"
rescue
redirect_to root_path, :alert => "Failed to login from #{provider.titleize}!"
end
end
end
end
It works fine on local server. Do I have have any way to trace the error, other than reading Heroku logs on the server?
There are two possible issues:
Incompatibility issue with solution, described here https://github.com/NoamB/sorcery/issues/147)
You missed
user_class
config in sorcery initializer. Sorcery definesload_from_provider
method on User class which should be specified in the config like this:config.user_class = User
. You can look at the code at Github
Hope that solved your problem! Cheers ;)
精彩评论