Skip to content

Latest commit

 

History

History
93 lines (67 loc) · 2.53 KB

README.md

File metadata and controls

93 lines (67 loc) · 2.53 KB

Omniauth::Wanliu

使用omniauth登陆系统, 支持ajax登陆

Installation

Add this line to your application's Gemfile:

gem 'omniauth-wanliu', :github => "wanliu/omniauth-wanliu"

And then execute:

$ bundle

Usage

  1. 在项目config目录新建sso.yml文件, 内容格式如下:

        accounts:
            provider_url: http://192.168.2.167:3002                     #帐户服务器地址
            app_id: 4224b3ed9c840c0d7b284f                              #授权id
            app_secret: oXIuKylcvf73EXe6R0Lhooxms2hfxcna7yfQs+9acHc=    #授权安全码
  2. config/initializers/omniauth.rb文件初始化middleware, 例如:

        info = OmniAuth::Wanliu.config
        Rails.application.config.middleware.use OmniAuth::Builder do 
            provider :WanliuId , info["app_id"], info["app_secret"]
        end

使用ajax登陆帐户配置

  1. ApplicationController 控制器包含ajax helper方法, 例如:

       include OmniAuth::Wanliu::AjaxHelpers 
  2. 在登陆过虑器方法添加ajax请求ajax_set_response_headers方法设置头部,例如:

        def login_required        
            if !current_user                
                respond_to do |format|    
                    format.js{
                        ajax_set_response_headers
                        render :text => :ok } 
                    format.html{ 
                        redirect_to '/auth/wanliuid'  }            
                end
            end
        end
  3. 客户端引用js文件, 例如:

  //在application.js添加如下代码
  //= require wanliu/ajax_auth_client.js

  //ajax验证, 传参平台登陆页面url
  AjaxAuthClient.setupRetrieveLoginUrlCallback(function(url){                
  })

  //注册登陆成功事件
  AjaxAuthClient.registreLoginSuccess(function(user){        
  })

  //注册加载用户注册回调事件
  AjaxAuthClient.registreLoadCreateUser(function(){
  })

  //注册加载用户找回密码回调事件
  AjaxAuthClient.registreLoadForgotPassword(function(){
  })

  //注册加载用户登陆回调事件
  AjaxAuthClient.registreLoadUserLogin(function(){
  })

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request