一直很想试下omniauth 我很菜,找到了这篇文章 http://railscasts.com/episodes/241-simple-omniauth 按其过程一路下来,注册好'CONSUMER_KEY', 'CONSUMER_SECRET' 最后rake routes时,说不能初始化: uninitialized constant OmniAuth::Strategies::Twitter 查到原因是还要添加omniauth-twitter这个gem gem 'omniauth-twitter'
这时,
rake routes时: ``` /auth/:provider/callback(.:format) {:controller=>"sessions", :action=>"create"} signout /signout(.:format) {:controller=>"sessions", :action=>"destroy"}
当我访问http://localhost:3000/auth/twitter 时,成功跳转到twitter去登录,登录成功后返回时,出错:
```Started GET "/auth/twitter/callback?oauth_token=1RubhwlvzjEE9mfYIGiKD1ZIGUNBDFqgkLfV4jo6bU&oauth_verifier=OEUA0qLLZNpYunwDL1BnWSydCo4IbnUYqOCTzZ33goo" for 127.0.0.1 at 2011-11-26 22:32:30 +0800
Processing by SessionsController#create as HTML
Parameters: {"oauth_token"=>"1RubhwlvzjEE9mfYIGiKD1ZIGUNBDFqgkLfV4jo6bU", "oauth_verifier"=>"OEUA0qLLZNpYunwDL1BnWSydCo4IbnUYqOCTzZ33goo", "provider"=>"twitter"}
User Load (0.5ms) SELECT `users`.* FROM `users` WHERE `users`.`provider` = 'twitter' AND `users`.`uid` = '18209844' LIMIT 1
Completed 500 Internal Server Error in 71ms
Started GET "/auth/failure?message=invalid_response" for 127.0.0.1 at 2011-11-26 22:32:34 +0800
ActionController::RoutingError (No route matches [GET] "/auth/failure"):
原因我查了很久,一直以为是twtter处配置的问题,后来,看了log,请求已经成功返回,带有验证后的数据,问题出在 ```user = User.find_by_provider_and_uid(auth["provider"], auth["uid"]) || User.create_with_omniauth(auth)
继续log往下找时,在User中的create_with_omniauth方法中,看到有auth["provider"],auth["uid"]以及auth["user_info"]["name"], 好吧,我将auth打印出来,我找到了provider,uid,就是找不到user_info,但我找到了name... 我觉得我已经找到问题所在,auth["user_info"]["name"] 修改成 auth["name"] 后,重试果然成功
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。