Sha256: c8eb11a5fa004387db24a655cafdf6c102be37281420ad17da60543129639d0f
Contents?: true
Size: 1.92 KB
Versions: 5
Compression:
Stored size: 1.92 KB
Contents
class OauthMr < Oauth def auth_request step = :step1, add_params = nil uri = URI CONFIG[:oauth][@name][:auth][step][:uri] params = CONFIG[:oauth][@name][:auth][:united_params].merge(CONFIG[:oauth][@name][:auth][step].except(:uri)).merge({redirect_uri: @verify_url, state: @key}) # для второго шага params.merge!(add_params) unless add_params.nil? case step when :step1 uri.query = URI.encode_www_form params uri.to_s when :step2 oauth_access_card_params Net::HTTP.post_form uri, params end end def oauth_access_card_params result begin params = ActiveSupport::JSON.decode(result.body) unless params['error'].present? add_info = get_user_info({session_key: params['access_token'], uid: params['x_mailru_vid']}) { state: :ok, oauth_name: @name, oauth_uid: params['x_mailru_vid'], access_token: params['access_token'], token_expired: (DateTime.now + params['expires_in'].second).to_s(:db), photourl: add_info['has_pic'].to_i == 0 ? nil : add_info['pic_128'] } else error_response "#{params['error']}:#{params['error_description']} #{params} #{result.body}" end rescue Exception => error error_response "rescue #{error.message} #{params} #{result.body} #{add_info}" end end def get_user_info access_params uri = URI CONFIG[:oauth][@name][:api][:get_user_info][:uri] params = CONFIG[:oauth][@name][:api][:get_user_info][:params] params.merge!(access_params) unless access_params.nil? sig = Digest::MD5.hexdigest params.sort.map{|k,v| "#{k}=#{v}"}.join() + CONFIG[:oauth][@name][:auth][:step2][:client_secret] # охуенная подпись ! params = params.merge({sig: sig}) uri.query = URI.encode_www_form params result = Net::HTTP.get_response uri ActiveSupport::JSON.decode(result.body)[0] end end
Version data entries
5 entries across 5 versions & 1 rubygems