Created
December 8, 2011 08:02
-
-
Save eirworks/1446424 to your computer and use it in GitHub Desktop.
Workaround in Twitter Omniauth using Omniauth v1+ (Rails)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# In new Twitter Omniauth, you may encounter errors, first, please check the Omniauth env | |
auth = request.env["rack.auth"] #this is incorrect | |
auth = request.env["omniauth.auth"] #this is correct | |
# Another error I found is: 401 Unauthorized | |
# which is can be fixed in ROOT/config/initializer/omniauth.rb | |
# This is incorrect | |
Rails.application.config.middleware.use OmniAuth::Builder do | |
provider :twitter, ENV['9S7MMaalIvDvFMOwwofF3w'], ENV['DQNsz3zzqvuFriHJYi8s2lm5WMzH4vFwWNkkdtUaNuA'] | |
end | |
# This is correct | |
Rails.application.config.middleware.use OmniAuth::Builder do | |
provider :twitter, '9S7MMaalIvDvFMOwwofF3w', 'DQNsz3zzqvuFriHJYi8s2lm5WMzH4vFwWNkkdtUaNuA' | |
end | |
# The last one I struggle is error that shows this | |
# http://localhost:3000/auth/failure?message=invalid_response | |
# in your url (if you are not yet set route auth/failure elsewhere). | |
# I suspect this is because Omniauth surpress errors. So what you want to do is | |
# check your session controller (or wherever the auth/provider_name/callback is routed) | |
# notice this: | |
auth = request.env["omniauth.auth"] | |
# to get user ID, name, etc, you might use | |
username = auth['user_info']['name'] | |
# which is now incorrect and you can get username or else using: | |
username = auth['info']['name'] | |
# and now everything works for me... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment