Skip to content

Commit

Permalink
connecting works
Browse files Browse the repository at this point in the history
  • Loading branch information
jaigouk committed Nov 30, 2011
1 parent 460e799 commit 149afbf
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 49 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source "http://rubygems.org"
# Specify your gem's dependencies in omniauth-intuit.gemspec
gemspec

gem 'yajl-ruby', :require => 'yajl'
gem 'crack'

group :development, :test do
gem "ruby-debug19", :platforms => :mri_19, :require => 'ruby-debug'
Expand Down
4 changes: 3 additions & 1 deletion example/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ source :rubygems

gem 'sinatra'
gem 'multi_json'
gem 'yajl-ruby', :require => 'yajl'
gem 'crack'
gem 'rack-ssl-enforcer'

gem 'omniauth-intuit', :path => '../'
#gem 'omniauth-intuit'
13 changes: 11 additions & 2 deletions example/config.ru
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ Bundler.require

require 'sinatra/base'
require 'omniauth-intuit'
require 'yaml'
require 'yajl'
require 'crack'
require 'rack-ssl-enforcer'


class App < Sinatra::Base
get '/' do
Expand All @@ -19,6 +20,13 @@ class App < Sinatra::Base
end

get '/auth/:provider/callback' do

puts "================"
puts params[:oauth_token]
puts params[:oauth_verifier]
puts params[:realmId]
puts params[:dataSource]
puts "================"
content_type 'application/json'
MultiJson.encode(request.env)
end
Expand All @@ -30,6 +38,7 @@ class App < Sinatra::Base
end

use Rack::Session::Cookie
# use Rack::SslEnforcer

config = YAML.load(File.read('config.yml'))
use OmniAuth::Builder do
Expand Down
55 changes: 36 additions & 19 deletions lib/omniauth/strategies/intuit.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'omniauth/strategies/oauth'

require 'crack'
module OmniAuth
module Strategies
class Intuit < OmniAuth::Strategies::OAuth
Expand All @@ -12,24 +12,41 @@ class Intuit < OmniAuth::Strategies::OAuth
:authorize_url => "https://workplace.intuit.com/Connect/Begin"
}

uid{ raw_info['id'] }

info do
{
:first_name => raw_info['firstName'],
:last_name => raw_info['lastName'],
:name => "#{raw_info['firstName']} #{raw_info['lastName']}",
:email => raw_info['email']
}
end

extra do
{ 'raw_info' => raw_info }
end

def raw_info
@raw_info ||= MultiJson.decode(access_token.get("https://workplace.intuit.com/Connect").body)
end
# uid{ raw_info['id'] }

# info do
# {
# :first_name => raw_info['firstName'],
# :last_name => raw_info['lastName'],
# :name => "#{raw_info['firstName']} #{raw_info['lastName']}",
# :email => raw_info['email'],
# :data_source => raw_info['dataSource'],
# :oauth_verifier => raw_info['oauth_verifier'],
# :realm_id => raw_info['realmId']
#
# }
# end
#
# extra do
# { 'raw_info' => raw_info }
# end
#
# def raw_info
# # access_token.get(path, headers={})
# # dataSource
# # "QBO"
# # oauth_token
# # "qyprdhjNbeM7UGDHYrgSvwqCRUQP0nZejdHw3IIFTaHY8mj5"
# # oauth_verifier
# # "ee3njpe"
# # realmId
# # "313247180"
#
# puts "==================="
# # access_token.get("/auth/intuit/callback").body
# puts "==================="
# @raw_info ||= Crack::XML.parse(access_token.get("").body)["RestResponse"]
# end
end
end
end
Expand Down
26 changes: 0 additions & 26 deletions spec/omniauth/strategies/intuit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,4 @@
end
end

context '#uid' do
before :each do
subject.stub(:raw_info) { { 'id' => '123' } }
end

it 'returns the id from raw_info' do
subject.uid.should eq('123')
end
end

describe '#info' do
before :each do
@raw_info ||= { 'firstName' => 'Fred', 'lastName' => 'Smith' }
subject.stub(:raw_info) { @raw_info }
end

context 'when data is present in raw info' do
it 'returns the first name' do
subject.info[:first_name].should eq('Fred')
end

it 'returns the last name' do
subject.info[:last_name].should eq('Smith')
end
end
end
end

0 comments on commit 149afbf

Please sign in to comment.