开发者

Rails & Omniauth: Twitter /auth/failure?message=invalid_response

开发者 https://www.devze.com 2023-03-25 23:21 出处:网络
I\'m using omniauth to implement twitter authentication in my application. I have facebook authentication working, and I know where the code for twitter authentication 开发者_C百科fails, but I can\'t

I'm using omniauth to implement twitter authentication in my application. I have facebook authentication working, and I know where the code for twitter authentication 开发者_C百科fails, but I can't figure out why!

Twitter does not provide an email address, and my site authenticates based on email/pw, so I only allow users to add a Twitter account to a pre-existing account, created by signing-up on the site or through facebook.

This is the relevant code, part of my services_controller.rb:

logger.info("USER SIGNED IN")
auth = Service.find_by_provider_and_uid(provider, uid)
logger.info("AUTH: #{auth}")
#If user is signed in but does not have this service linked to his account
if !auth
  logger.info("AUTH IS NULL, SERVICE NOT LINKED TO ACCOUNT")
  logger.info("PROVIDER: #{provider}, UID: #{uid}, EMAIL: #{email}")
  user.services.create!(:provider => provider, :uid => uid, :uemail => email)
  logger.info("SERVICE CREATED")
  flash[:notice] = 'Sign in via ' + provider.capitalize + ' has been added to your account.'
  redirect_to services_path

Now, I the last thing I see in my log is:

AUTH IS NULL, SERVICE NOT LINKED TO ACCOUNT
PROVIDER: twitter, UID: 3195xxxxx, EMAIL: 
Completed   in 231ms
Started GET "/auth/failure?message=invalid_response" for 127.0.0.1 at 2011-08-05 20:52:30 +0530
ActionController::RoutingError (No route matches "/auth/failure"):

As you can see from the code above, this means that the line user.services.create!(...) fails, which is why I never see SERVICE CREATED in my log. I don't know why it fails though. I know the email variable is empty, but that is expected since Twitter does not provide emails. I have even tried replacing :uemail => email with :uemail => "validemail@gmail.com", but I still get the same output.


Probably the line

user.services.create!(:provider => provider, :uid => uid, :uemail => email)

raises an exception, so following code is not executed. Have you tried that line using the console?

Maybe it could be a validation failure, something like validate_uniqueness, or validates_presence_of. It could be a duplicated uid in your services table.

Running that line from the console will give you the answer.

0

精彩评论

暂无评论...
验证码 换一张
取 消