rails3.2 omniauth_china各平台授权

1.安装

方法一:gem install omniauth_china

方法二:gemfile中添加 gem 'omniauth_china'

 

2.在配置文件config/application.rb文件中

 class Application < Rails::Application #这句话后面添加如下代码: require 'oa-oauth' config.middleware.use OmniAuth::Strategies::Tqq, 'api_key', 'api_secret' #qq config.middleware.use OmniAuth::Strategies::Tsina, 'api_key', 'api_secret'  #sina
 config.middleware.use OmniAuth::Strategies::Renren, 'api_key',  'api_secret'   #renren

 

3.config/routes文件中,添加

 

  match "/auth/:provider/callback" => "login#callback"   #成功所调用action
  match "/auth/failure" => "login#failure"  #失败所调用的action

 

4.views文件中,写法如下:

 

<%=link_to "微博登录".html_safe, "/auth/tsina"%>
<%=link_to "QQ登录".html_safe, "/auth/tqq"%>
<%=link_to "人人登录".html_safe, "/auth/renren"%>

 

5.controller文件中,写法如下:

 

class LoginController < ApplicationController
    
   def callback
	auth=request.env['omniauth.auth'] #获取授权信息
   end

6.因为qq授权用oauth2.0,而omniauth-qq-0.2.1插件是有带oauth2.0方法,

可以通过qq_connect

config.middleware.use OmniAuth::Strategies::QqContent, 'api_key', 'api_secret', #qq

 

参考网站:https://github.com/he9qi/omniauth_china

你可能感兴趣的:(rails3)