Gem "Omniauth pure"上,实现国产 OAuth 认证

yume · 2012年11月01日 · 最后由 lulalala 回复于 2014年09月29日 · 6243 次阅读

在"Omniauth pure"的基础上,实现国产 OAuth 认证(weibo,tqq,douban,renren),除了对代码的调整,还有对 weibo,tqq,douban,renren 创建授权应用。各位,在 weibo 等 OAuth 认证时,会出现各种各样的授权问题,特头疼。还是慢慢解决吧。

该 project 增加如下:

"Omniauth pure" 的来源:https://github.com/markusproske/omniauth_pure

1. Gemfile 文件,增加:

针对 weibo,tqq 认证,直接在 Gemfile 中 gem 就好,在 Omniauth 的 List-of-Strategies 中即可找到。(https://github.com/intridea/omniauth/wiki/List-of-Strategies

2. lib 目录下,增加 mniauth / strategies 目录,存放 douban.rb,renren.rb 来源于

https://github.com/liluo/omniauth-douban-oauth2/blob/master/lib/omniauth/strategies/douban.rb https://github.com/ballantyne/omniauth-renren/blob/master/lib/omniauth/strategies/renren.rb

3. config/environments/development.rb,增加:

注:KEY,SECRET 值,请用相应的授权应用的值。

4 app/views/layouts/application.html.erb,增加:

5. app/controllers/services_controller.rb,增加:

并在该 controller 的 create 方法中,增加

增加上述信息,就可以实现相应的认证。

在实现过程中,总是出现版本依赖问题,或者授权问题,俺这个新手,又对 OAuth 认证很茫然。老大经常叫我“郁闷(yume)”,哎,总归如此。

1. douban 认证 (采用的是 auth2)

在 Omniauth 的 List-of-Strategies 没有支持 douban 的 gem,但是在 Github 目录下能搜索到两组:

1)ballantyne/omniauth-douban

使用时,总是提示:400 Bad Request (OAuth::Unauthorized) (很明显它是依赖的 omniauth-auth) Scott Ballantyne 提到:originally douban used oauth 1, but now it uses oauth2. maybe try https://github.com/liluo/omniauth-douban-oauth2 说实话,应该早点找 Scott Ballantyne(@shichuan),要不就不会一直看着 400 Bad Request (OAuth::Unauthorized),郁闷了很久。

2)liluo/omniauth-douban-oauth2

gem 后,在 bundle install 时,会提示:omniauth-auth2 版本冲突问题。 所以,老大就建议直接引用 liluo/omniauth-douban-oauth2 / lib / omniauth / strategies / douban.rb,将该文件放在 Omniauth pure/ lib / omniauth / strategies 下,然后在 config/environments/development.rb 中 provider :douban, ENV['DOUBAN_KEY'], ENV['DOUBAN_SECRET'] 之前,先 require 'omniauth/strategies/douban.rb',其他并无任何改动,这样就可以实现 douban 认证

2. renren 认证 (采用的是 auth2)

1) ballantyne / omniauth-renren

renren 认证时,同样采用 douban 认证的方式,但是觉得一切都 ok 时,可总是提示: error:invalid_request error_description:Invalid redirect_uri. 原因在于没有在授权 renren 应用时,没有填写对应用根地址,应用回调地址。

weibo,tqq,douban,renren 的认证总算搞定了,说实话,对 OAuth 认证,具体的信息还是不明确。明天,另一位同事来了,就可以进行下面的工作了。

Fighting,Fighting,Fighting.人就是在总是在各式各样的鼓励下,不断茁壮成长的。

人生,其实也挺简单!

上述,纯属记录。(有任何問題,再說)

#1 楼 @yesmeck 无视中~~~

我关心的是头像是楼主本人不?

敢问楼主编辑器的 colorscheme 是什么呢

#3 楼 @fresh_fish 如果你觉得应该是本人,那就是本人啰。

#4 楼 @ganweiliang redcar 编辑器,Theme 为 Django。

要是在北京就好了

#7 楼 @sundevilyang 这个年代,距离还是问题吗?

#9 楼 @yume 因为我最近和 railsgirls 取得了联系,可能要在北京举办一些针对 girls 的活动

#11 楼 @sundevilyang 看来这次没有机会了。

#12 楼 @yume 话说 距离不是问题?my god, 从来没想过要在 ruby china 里面泡妞。搞不好就惹来一群基友。你要在北京是有机会的,成都最近也有 rails-girls 的活动

………………汗颜,想多了,只是说,可以谈 ruby 的问题,本来我就是个新手,要问的很多。。。。

I use omniauth and omniauth-salesfore, rails s run the app, it show s ssl error

我想问一下, 人人的有的 API 接口用的时候,先 Oauth 认证时候要 scope 参数吗?

我用如下 gem 包 https://github.com/lastomato/omniauth-xiaonei scope 是哪里配吗?

还有问一下。人人网的 gem 包是有两个,哪个好? https://github.com/lastomato/omniauth-xiaonei https://github.com/transist/omniauth-renren

想问一下 Omniauth pure 的优点是什么

需要 登录 后方可回复, 如果你还没有账号请 注册新账号