使用omniauth登陆系统, 支持ajax登陆
Add this line to your application's Gemfile:
gem 'omniauth-wanliu', :github => "wanliu/omniauth-wanliu"
And then execute:
$ bundle
-
在项目config目录新建
sso.yml
文件, 内容格式如下:accounts: provider_url: http://192.168.2.167:3002 #帐户服务器地址 app_id: 4224b3ed9c840c0d7b284f #授权id app_secret: oXIuKylcvf73EXe6R0Lhooxms2hfxcna7yfQs+9acHc= #授权安全码
-
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
-
ApplicationController
控制器包含ajax helper方法, 例如:include OmniAuth::Wanliu::AjaxHelpers
-
在登陆过虑器方法添加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
-
客户端引用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(){
})
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request