omniauth-salesforce 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 09b903072b7e9b94e366fb7ff1a22b3c058a87d1
4
+ data.tar.gz: 20caac8cc1e94b718387f0744e265a6e457763cc
5
+ SHA512:
6
+ metadata.gz: 2058ec807e22afc966995ae504ec7ecefef72980812690d226795d125c9c27f5521a20dbf4b4146ef1d9feb609e75326c676b7a11b6c7fcca75871caab7d2278
7
+ data.tar.gz: 65662fa728868aec3a07786bcc77b471e1994af2ca33c495b618a4150ec354f8efd76a85b34c844c497026a694583f8e2d1d2b6b770267d993ebf66077e35158
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.2-p290@omniauth-salesforce --create
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'http://rubygems.org'
1
+ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in omniauth-salesforce.gemspec
4
4
  gemspec
@@ -0,0 +1,5 @@
1
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
2
+
3
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
4
+
5
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  [OmniAuth](https://github.com/intridea/omniauth) Strategy for [salesforce.com](salesforce.com).
4
4
 
5
+ Note: This is a fork of the [original](https://github.com/richardvanhook/omniauth-salesforce) project and is now the main repository for the omniauth-salesforce gem.
6
+
5
7
  ## See it in action
6
8
 
7
9
  [http://omniauth-salesforce-example.herokuapp.com](http://omniauth-salesforce-example.herokuapp.com)
@@ -10,14 +12,38 @@
10
12
 
11
13
  ## Basic Usage
12
14
 
13
- require "sinatra"
14
- require "omniauth"
15
- require "omniauth-salesforce"
16
-
17
- class MyApplication < Sinatra::Base
18
- use Rack::Session
19
- use OmniAuth::Builder do
20
- provider :salesforce, ENV['SALESFORCE_KEY'], ENV['SALESFORCE_SECRET']
21
- end
22
- end
23
-
15
+ ```ruby
16
+ require "sinatra"
17
+ require "omniauth"
18
+ require "omniauth-salesforce"
19
+
20
+ class MyApplication < Sinatra::Base
21
+ use Rack::Session
22
+ use OmniAuth::Builder do
23
+ provider :salesforce, ENV['SALESFORCE_KEY'], ENV['SALESFORCE_SECRET']
24
+ end
25
+ end
26
+ ```
27
+
28
+ ## Including other sites
29
+
30
+ ```ruby
31
+ use OmniAuth::Builder do
32
+ provider :salesforce,
33
+ ENV['SALESFORCE_KEY'],
34
+ ENV['SALESFORCE_SECRET']
35
+ provider OmniAuth::Strategies::SalesforceSandbox,
36
+ ENV['SALESFORCE_SANDBOX_KEY'],
37
+ ENV['SALESFORCE_SANDBOX_SECRET']
38
+ provider OmniAuth::Strategies::SalesforcePreRelease,
39
+ ENV['SALESFORCE_PRERELEASE_KEY'],
40
+ ENV['SALESFORCE_PRERELEASE_SECRET']
41
+ provider OmniAuth::Strategies::DatabaseDotCom,
42
+ ENV['DATABASE_DOT_COM_KEY'],
43
+ ENV['DATABASE_DOT_COM_SECRET']
44
+ end
45
+ ```
46
+
47
+ ## Resources
48
+
49
+ * [Article: Digging Deeper into OAuth 2.0 on Force.com](http://wiki.developerforce.com/index.php/Digging_Deeper_into_OAuth_2.0_on_Force.com)
@@ -1,5 +1,5 @@
1
1
  module OmniAuth
2
2
  module Salesforce
3
- VERSION = "1.0.3"
3
+ VERSION = "1.0.4"
4
4
  end
5
5
  end
@@ -1,10 +1,12 @@
1
1
  require 'omniauth-oauth2'
2
+ require 'openssl'
3
+ require 'base64'
2
4
 
3
5
  module OmniAuth
4
6
  module Strategies
5
7
  class Salesforce < OmniAuth::Strategies::OAuth2
6
8
 
7
- MOBILE_USER_AGENTS = 'webos|ipod|iphone|mobile'
9
+ MOBILE_USER_AGENTS = 'webos|ipod|iphone|ipad|android|blackberry|mobile'
8
10
 
9
11
  option :client_options, {
10
12
  :site => 'https://login.salesforce.com',
@@ -15,7 +17,8 @@ module OmniAuth
15
17
  :scope,
16
18
  :display,
17
19
  :immediate,
18
- :state
20
+ :state,
21
+ :prompt
19
22
  ]
20
23
 
21
24
  def request_phase
@@ -29,6 +32,15 @@ module OmniAuth
29
32
  super
30
33
  end
31
34
 
35
+ def auth_hash
36
+ signed_value = access_token.params['id'] + access_token.params['issued_at']
37
+ raw_expected_signature = OpenSSL::HMAC.digest('sha256', options.client_secret, signed_value)
38
+ expected_signature = Base64.strict_encode64 raw_expected_signature
39
+ signature = access_token.params['signature']
40
+ fail! "Salesforce user id did not match signature!" unless signature == expected_signature
41
+ super
42
+ end
43
+
32
44
  uid { raw_info['id'] }
33
45
 
34
46
  info do
@@ -62,7 +74,9 @@ module OmniAuth
62
74
  extra do
63
75
  raw_info.merge({
64
76
  'instance_url' => access_token.params['instance_url'],
65
- 'pod' => access_token.params['instance_url']
77
+ 'pod' => access_token.params['instance_url'],
78
+ 'signature' => access_token.params['signature'],
79
+ 'issued_at' => access_token.params['issued_at']
66
80
  })
67
81
  end
68
82
 
@@ -6,7 +6,7 @@ Gem::Specification.new do |gem|
6
6
  gem.email = ["rvanhook@salesforce.com"]
7
7
  gem.description = %q{OmniAuth strategy for salesforce.com.}
8
8
  gem.summary = %q{OmniAuth strategy for salesforce.com.}
9
- gem.homepage = "https://github.com/richardvanhook/omniauth-salesforce"
9
+ gem.homepage = "https://github.com/realdoug/omniauth-salesforce"
10
10
 
11
11
  gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
12
  gem.files = `git ls-files`.split("\n")
@@ -14,6 +14,7 @@ Gem::Specification.new do |gem|
14
14
  gem.name = "omniauth-salesforce"
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = OmniAuth::Salesforce::VERSION
17
+ gem.license = "MIT"
17
18
 
18
19
  gem.add_dependency 'omniauth', '~> 1.0'
19
20
  gem.add_dependency 'omniauth-oauth2', '~> 1.0'
@@ -1,7 +1,217 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe OmniAuth::Strategies::Salesforce do
4
- it 'should do some testing' do
5
- pending
6
- end
4
+ strategy = nil
5
+ before do
6
+ OmniAuth.config.test_mode = true
7
+ rack_app = []
8
+ rack_app.stub :call
9
+ strategy = OmniAuth::Strategies::Salesforce.new rack_app, 'Consumer Key', 'Consumer Secret'
10
+ end
11
+ describe "request_phase" do
12
+ env = nil
13
+ before do
14
+ env = {
15
+ 'rack.session' => {},
16
+ 'HTTP_USER_AGENT' => 'unknown',
17
+ 'REQUEST_METHOD' => 'GET',
18
+ 'rack.input' => '',
19
+ 'rack.url_scheme' => 'http',
20
+ 'SERVER_NAME' => 'server.example',
21
+ 'QUERY_STRING' => 'code=xxxx',
22
+ 'SCRIPT_NAME' => '',
23
+ 'SERVER_PORT' => 80
24
+ }
25
+ end
26
+ context "when using a mobile browser" do
27
+ user_agents = {
28
+ :Pre => "Mozilla/5.0 (webOS/1.4.0; U; en-US) AppleWebKit/532.2 (KHTML, like Gecko) Version/1.0 Safari/532.2 Pre/1.1",
29
+ :iPod => "Mozilla/5.0 (iPod; U; CPU like Mac OS X; en) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/4A93 Safari/419.3",
30
+ :iPhone => "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543 Safari/419.3",
31
+ :iPad => "Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10",
32
+ :Nexus => "Mozilla/5.0 (Linux; U; Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1",
33
+ :myTouch => "Mozilla/5.0 (Linux; U; Android 1.6; en-us; WOWMobile myTouch 3G Build/unknown) AppleWebKit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/525.20.1",
34
+ :Storm => "BlackBerry9530/4.7.0.148 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/105",
35
+ :Torch => "Mozilla/5.0 (BlackBerry; U; BlackBerry 9810; en-US) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.0.0 Mobile Safari/534.11+",
36
+ :generic_mobile => "some mobile device"
37
+ }
38
+ user_agents.each_pair do |name, agent|
39
+ context "with the user agent from a #{name.to_s}" do
40
+ before do
41
+ env['HTTP_USER_AGENT'] = agent
42
+ strategy.call!(env)
43
+ strategy.request_phase
44
+ end
45
+ subject {strategy.options}
46
+ it "sets the :display option to 'touch'" do
47
+ subject[:display].should == 'touch'
48
+ end
49
+ end
50
+ end
51
+ end
52
+ context "when using a desktop browser" do
53
+ user_agents = {
54
+ :Chrome => "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.21 (KHTML, like Gecko) Chrome/19.0.1042.0 Safari/535.21",
55
+ :Safari => "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; de-at) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1",
56
+ :IE => "Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET CLR 1.0.3705; .NET CLR 1.1.4322)",
57
+ :anything_else => "unknown"
58
+ }
59
+ user_agents.each_pair do |name, agent|
60
+ context "with the user agent from #{name.to_s}" do
61
+ before do
62
+ env['HTTP_USER_AGENT'] = agent
63
+ strategy.call!(env)
64
+ strategy.request_phase
65
+ end
66
+ subject {strategy.options}
67
+ it "sets the :display option to 'page'" do
68
+ subject[:display].should == 'page'
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+ describe "callback phase" do
75
+ raw_info = nil
76
+ before do
77
+ raw_info = {
78
+ 'id' => 'salesforce id',
79
+ 'display_name' => 'display name',
80
+ 'email' => 'email',
81
+ 'nick_name' => 'nick name',
82
+ 'first_name' => 'first name',
83
+ 'last_name' => 'last name',
84
+ 'photos' => {'thumbnail' => '/thumbnail/url'},
85
+ 'urls'=> {
86
+ "enterprise" => "https://salesforce.example/services",
87
+ "metadata" => "https://salesforce.example/services"
88
+ }
89
+ }
90
+ client = OAuth2::Client.new 'id', 'secret', {:site => 'example.com'}
91
+ access_token = OAuth2::AccessToken.from_hash client, {
92
+ 'access_token' => 'token',
93
+ 'instance_url' => 'http://instance.salesforce.example',
94
+ 'signature' => 'invalid',
95
+ 'issued_at' => '1296458209517'
96
+ }
97
+ strategy.stub(:raw_info) { raw_info }
98
+ strategy.stub(:access_token) { access_token }
99
+ end
100
+ describe "uid" do
101
+ it "sets the id" do
102
+ strategy.uid.should == raw_info['id']
103
+ end
104
+ end
105
+ describe "info" do
106
+ subject { strategy.info }
107
+ it "returns an info hash" do
108
+ subject.should_not be_nil
109
+ end
110
+ it "sets name" do
111
+ subject['name'].should == raw_info['display_name']
112
+ end
113
+ it "sets email" do
114
+ subject['email'].should == raw_info['email']
115
+ end
116
+ it "sets nickname" do
117
+ subject['nickname'].should == raw_info['nick_name']
118
+ end
119
+ it "sets first_name" do
120
+ subject['first_name'].should == raw_info['first_name']
121
+ end
122
+ it "sets last_name" do
123
+ subject['last_name'].should == raw_info['last_name']
124
+ end
125
+ it "sets location" do
126
+ subject['location'].should == ''
127
+ end
128
+ it "sets description" do
129
+ subject['description'].should == ''
130
+ end
131
+ it "sets image" do
132
+ subject['image'].should == raw_info['photos']['thumbnail'] + "?oauth_token=#{strategy.access_token.token}"
133
+ end
134
+ it "sets phone" do
135
+ subject['phone'].should == ''
136
+ end
137
+ it "sets urls" do
138
+ subject['urls'].should == raw_info['urls']
139
+ end
140
+ end
141
+ describe "credentials" do
142
+ subject { strategy.credentials }
143
+ it "sets token" do
144
+ subject['token'].should == strategy.access_token.token
145
+ end
146
+ it "sets instance_url" do
147
+ subject['instance_url'].should == strategy.access_token.params["instance_url"]
148
+ end
149
+ context "given a refresh token" do
150
+ it "sets refresh_token" do
151
+ subject['refresh_token'].should == strategy.access_token.refresh_token
152
+ end
153
+ end
154
+ context "when not given a refresh token" do
155
+ it "does not set a refresh token" do
156
+ subject['refresh_token'].should be_nil
157
+ end
158
+ end
159
+ end
160
+ describe "extra" do
161
+ subject { strategy.extra }
162
+ it "sets instance_url" do
163
+ subject['instance_url'].should == strategy.access_token.params['instance_url']
164
+ end
165
+ it "sets pod" do
166
+ subject['pod'].should == strategy.access_token.params['instance_url']
167
+ end
168
+ it "sets signature" do
169
+ subject['signature'].should == strategy.access_token.params['signature']
170
+ end
171
+ it "sets issued_at" do
172
+ subject['issued_at'].should == strategy.access_token.params['issued_at']
173
+ end
174
+ end
175
+ describe "user id validation" do
176
+ client_id = nil
177
+ issued_at = nil
178
+ signature = nil
179
+ instance_url = 'http://instance.salesforce.example'
180
+ before do
181
+ client_id = "https://login.salesforce.com/id/00Dd0000000d45TEBQ/005d0000000fyGPCCY"
182
+ issued_at = "1331142541514"
183
+ signature = Base64.strict_encode64(OpenSSL::HMAC.digest('sha256', strategy.options.client_secret, client_id + issued_at))
184
+ end
185
+ context "when the signature does not match" do
186
+ before do
187
+ access_token = OAuth2::AccessToken.from_hash strategy.access_token.client, {
188
+ 'id' => 'forged client id',
189
+ 'issued_at' => issued_at,
190
+ 'instance_url' => 'http://instance.salesforce.example',
191
+ 'signature' => signature
192
+ }
193
+ strategy.stub(:access_token) { access_token }
194
+ end
195
+ it "should call fail!" do
196
+ strategy.should_receive(:fail!)
197
+ strategy.auth_hash
198
+ end
199
+ end
200
+ context "when the signature does match" do
201
+ before do
202
+ access_token = OAuth2::AccessToken.from_hash strategy.access_token.client, {
203
+ 'id' => client_id,
204
+ 'issued_at' => issued_at,
205
+ 'instance_url' => 'http://instance.salesforce.example',
206
+ 'signature' => signature
207
+ }
208
+ strategy.stub(:access_token) { access_token }
209
+ end
210
+ it "should not fail" do
211
+ strategy.should_not_receive(:fail!)
212
+ strategy.auth_hash
213
+ end
214
+ end
215
+ end
216
+ end
7
217
  end
metadata CHANGED
@@ -1,82 +1,99 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-salesforce
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
5
- prerelease:
4
+ version: 1.0.4
6
5
  platform: ruby
7
6
  authors:
8
7
  - Richard Vanhook
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2011-12-08 00:00:00.000000000 Z
11
+ date: 2013-05-27 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: omniauth
16
- requirement: &2156089220 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
21
19
  version: '1.0'
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *2156089220
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
25
27
  - !ruby/object:Gem::Dependency
26
28
  name: omniauth-oauth2
27
- requirement: &2156088020 !ruby/object:Gem::Requirement
28
- none: false
29
+ requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
31
  - - ~>
31
32
  - !ruby/object:Gem::Version
32
33
  version: '1.0'
33
34
  type: :runtime
34
35
  prerelease: false
35
- version_requirements: *2156088020
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
36
41
  - !ruby/object:Gem::Dependency
37
42
  name: rspec
38
- requirement: &2156087100 !ruby/object:Gem::Requirement
39
- none: false
43
+ requirement: !ruby/object:Gem::Requirement
40
44
  requirements:
41
45
  - - ~>
42
46
  - !ruby/object:Gem::Version
43
47
  version: '2.7'
44
48
  type: :development
45
49
  prerelease: false
46
- version_requirements: *2156087100
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.7'
47
55
  - !ruby/object:Gem::Dependency
48
56
  name: rack-test
49
- requirement: &2156086240 !ruby/object:Gem::Requirement
50
- none: false
57
+ requirement: !ruby/object:Gem::Requirement
51
58
  requirements:
52
- - - ! '>='
59
+ - - '>='
53
60
  - !ruby/object:Gem::Version
54
61
  version: '0'
55
62
  type: :development
56
63
  prerelease: false
57
- version_requirements: *2156086240
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
58
69
  - !ruby/object:Gem::Dependency
59
70
  name: simplecov
60
- requirement: &2156085680 !ruby/object:Gem::Requirement
61
- none: false
71
+ requirement: !ruby/object:Gem::Requirement
62
72
  requirements:
63
- - - ! '>='
73
+ - - '>='
64
74
  - !ruby/object:Gem::Version
65
75
  version: '0'
66
76
  type: :development
67
77
  prerelease: false
68
- version_requirements: *2156085680
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: webmock
71
- requirement: &2156085120 !ruby/object:Gem::Requirement
72
- none: false
85
+ requirement: !ruby/object:Gem::Requirement
73
86
  requirements:
74
- - - ! '>='
87
+ - - '>='
75
88
  - !ruby/object:Gem::Version
76
89
  version: '0'
77
90
  type: :development
78
91
  prerelease: false
79
- version_requirements: *2156085120
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
80
97
  description: OmniAuth strategy for salesforce.com.
81
98
  email:
82
99
  - rvanhook@salesforce.com
@@ -86,8 +103,10 @@ extra_rdoc_files: []
86
103
  files:
87
104
  - .gitignore
88
105
  - .rspec
106
+ - .rvmrc
89
107
  - Gemfile
90
108
  - Guardfile
109
+ - LICENSE.md
91
110
  - README.md
92
111
  - Rakefile
93
112
  - lib/omniauth-salesforce.rb
@@ -96,29 +115,29 @@ files:
96
115
  - omniauth-salesforce.gemspec
97
116
  - spec/omniauth/strategies/salesforce_spec.rb
98
117
  - spec/spec_helper.rb
99
- homepage: https://github.com/richardvanhook/omniauth-salesforce
100
- licenses: []
118
+ homepage: https://github.com/realdoug/omniauth-salesforce
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
101
122
  post_install_message:
102
123
  rdoc_options: []
103
124
  require_paths:
104
125
  - lib
105
126
  required_ruby_version: !ruby/object:Gem::Requirement
106
- none: false
107
127
  requirements:
108
- - - ! '>='
128
+ - - '>='
109
129
  - !ruby/object:Gem::Version
110
130
  version: '0'
111
131
  required_rubygems_version: !ruby/object:Gem::Requirement
112
- none: false
113
132
  requirements:
114
- - - ! '>='
133
+ - - '>='
115
134
  - !ruby/object:Gem::Version
116
135
  version: '0'
117
136
  requirements: []
118
137
  rubyforge_project:
119
- rubygems_version: 1.8.5
138
+ rubygems_version: 2.0.3
120
139
  signing_key:
121
- specification_version: 3
140
+ specification_version: 4
122
141
  summary: OmniAuth strategy for salesforce.com.
123
142
  test_files:
124
143
  - spec/omniauth/strategies/salesforce_spec.rb