2013-10-30 34 views
3

我找遍了所有周围的网,如何创建omniauth自定义提供..我succedded部分..如何创建自定义omniauth提供商(如何返回数据)

我创建了一个宝石,和它的工作完美,除了一部分,我无法理解如何将收集的数据恢复会话控制器,像其他供应商做..

这里是权威性的宝石代码:

require 'multi_json' 
require 'digest/md5' 
require 'rest-client' 

module OmniAuth 
    module Strategies 
    class Providername < OmniAuth::Strategies::OAuth 
     attr_accessor :app_id, :api_key, :auth 

     def initialize(app, app_id = nil, api_key = nil, options = {}) 
     super(app, :providername) 
     @app_id = app_id 
     @api_key = api_key 
     end 

     protected 

     def request_phase 
     redirect "http://valid_url" 
     end 

     def callback_phase 
     if request.params['code'] && request.params['status'] == 'ok' 
      response = RestClient.get("http://valid_url2/?code=#{request.params['auth_code']}") 
      auth = MultiJson.decode(response.to_s) 
      unless auth['error'] 
      @auth_data = auth 

      if @auth_data 
       @return_data = OmniAuth::Utils.deep_merge(super, { 
        'uid' => @auth_data['uid'], 
        'nickname' => @auth_data['nick'], 
        'user_info' => { 
        'first_name' => @auth_data['name'], 
        'last_name' => @auth_data['surname'], 
        'location' => @auth_data['place'], 
        }, 
        'credentials' => { 
        'apikey' => @auth_data['apikey'] 
        }, 
        'extra' => {'user_hash' => @auth_data} 
       }) 
      end 

      end 
     else 
      fail!(:invalid_request) 
     end 
     rescue Exception => e 
     fail!(:invalid_response, e) 
     end 

    end 
    end 
end 

,在这里我叫它在我的初始化程序中:

Rails.application.config.middleware.use OmniAuth::Builder do 
    provider "providername", Settings.providers.providername.app_id, Settings.providers.providername.app_secret 
end 
在这段代码

,一切工作正常,到目前为止,供应商被调用,我从供应商的信息,我创建了一个哈希(@auth_data)与信息,但我怎么回吧

+0

这是有趣的,你得到这个地方? – 0bserver07

+0

@observer对不起,不.. – ExClouds

回答