omniauth-desk 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/omniauth/strategies/desk.rb +25 -4
- data/lib/omniauth-desk/version.rb +1 -1
- data/spec/omniauth/strategies/desk_spec.rb +60 -15
- metadata +18 -18
@@ -6,6 +6,8 @@ module OmniAuth
|
|
6
6
|
# An omniauth 1.0 strategy for Desk.com authorization
|
7
7
|
class Desk < OmniAuth::Strategies::OAuth
|
8
8
|
option :name, 'desk'
|
9
|
+
option :site, nil
|
10
|
+
option :site_param, 'desk_site'
|
9
11
|
option :client_options, {
|
10
12
|
:authorize_path => '/oauth/authorize',
|
11
13
|
:request_token_path => '/oauth/request_token',
|
@@ -35,7 +37,7 @@ module OmniAuth
|
|
35
37
|
|
36
38
|
# Return info gathered from the verify_credentials API call
|
37
39
|
def raw_info
|
38
|
-
@raw_info ||= MultiJson.decode(access_token.get('/api/v1/account/verify_credentials.json').body)
|
40
|
+
@raw_info ||= MultiJson.decode(access_token.get('/api/v1/account/verify_credentials.json').body) if access_token
|
39
41
|
rescue ::Errno::ETIMEDOUT
|
40
42
|
raise ::Timeout::Error
|
41
43
|
end
|
@@ -45,13 +47,32 @@ module OmniAuth
|
|
45
47
|
@user_info ||= raw_info.nil? ? {} : raw_info['user']
|
46
48
|
end
|
47
49
|
|
50
|
+
def identifier
|
51
|
+
session[:site] = options.client_options.site = options.site || validate_site(request.params[options.site_param.to_s])
|
52
|
+
session[:site] = options.client_options.site = nil if options.client_options.site == ''
|
53
|
+
options.client_options.site
|
54
|
+
end
|
55
|
+
|
56
|
+
def validate_site(site)
|
57
|
+
if site and site != ''
|
58
|
+
"https://#{site}.desk.com"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def get_identifier
|
63
|
+
f = OmniAuth::Form.new :title => 'Desk.com Authorization'
|
64
|
+
f.text_field 'Desk.com Site', options.site_param.to_s
|
65
|
+
f.html '<p><strong>Hint:</strong> https://YOURSITE.desk.com'
|
66
|
+
f.button 'Login'
|
67
|
+
f.to_response
|
68
|
+
end
|
69
|
+
|
48
70
|
def request_phase
|
49
|
-
|
50
|
-
super
|
71
|
+
identifier ? super : get_identifier
|
51
72
|
end
|
52
73
|
|
53
74
|
def callback_phase
|
54
|
-
options
|
75
|
+
options.client_options.site = session[:site] if session[:site]
|
55
76
|
super
|
56
77
|
end
|
57
78
|
end
|
@@ -1,25 +1,70 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'omniauth-desk'
|
2
3
|
|
3
|
-
describe OmniAuth::Strategies::Desk do
|
4
|
-
|
5
|
-
OmniAuth::Strategies::Desk
|
4
|
+
describe OmniAuth::Strategies::Desk, :type => :strategy do
|
5
|
+
def app
|
6
|
+
strat = OmniAuth::Strategies::Desk
|
7
|
+
Rack::Builder.new {
|
8
|
+
use Rack::Session::Cookie
|
9
|
+
use strat
|
10
|
+
run lambda {|env| [404, {'Content-Type' => 'text/plain'}, [nil || env.key?('omniauth.auth').to_s]] }
|
11
|
+
}.to_app
|
6
12
|
end
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
13
|
+
|
14
|
+
describe '/auth/desk without a site URL' do
|
15
|
+
before do
|
16
|
+
get '/auth/desk'
|
11
17
|
end
|
12
|
-
|
13
|
-
it 'should
|
14
|
-
|
18
|
+
|
19
|
+
it 'should respond with OK' do
|
20
|
+
last_response.should be_ok
|
15
21
|
end
|
16
|
-
|
17
|
-
it 'should
|
18
|
-
|
22
|
+
|
23
|
+
it 'should respond with HTML' do
|
24
|
+
last_response.content_type.should == 'text/html'
|
19
25
|
end
|
20
26
|
|
21
|
-
it 'should
|
22
|
-
|
27
|
+
it 'should render an identifier URL input' do
|
28
|
+
last_response.body.should =~ %r{<input[^>]*desk_site}
|
23
29
|
end
|
24
30
|
end
|
31
|
+
|
32
|
+
describe 'followed by /auth/desk/callback' do
|
33
|
+
context 'successful' do
|
34
|
+
it 'should set provider to desk'
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'unsuccessful' do
|
38
|
+
before do
|
39
|
+
get '/auth/desk/callback'
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should be redirected to failure' do
|
43
|
+
last_response.should be_redirect
|
44
|
+
last_response.headers['Location'].should =~ %r{failure}
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# context "client options" do
|
50
|
+
# it 'should have correct name' do
|
51
|
+
# subject.options.name.should eq("desk")
|
52
|
+
# end
|
53
|
+
#
|
54
|
+
# it 'should have correct authorize path' do
|
55
|
+
# subject.options.client_options.authorize_path.should eq('/oauth/authorize')
|
56
|
+
# end
|
57
|
+
#
|
58
|
+
# it 'should have correct request token path' do
|
59
|
+
# subject.options.client_options.request_token_path.should eq('/oauth/request_token')
|
60
|
+
# end
|
61
|
+
#
|
62
|
+
# it 'should have correct access token path' do
|
63
|
+
# subject.options.client_options.access_token_path.should eq('/oauth/access_token')
|
64
|
+
# end
|
65
|
+
#
|
66
|
+
# it 'should have an empty user_info' do
|
67
|
+
# subject.user_info.should eq({})
|
68
|
+
# end
|
69
|
+
# end
|
25
70
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniauth-desk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-26 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: omniauth
|
16
|
-
requirement: &
|
16
|
+
requirement: &2166168760 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '1.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2166168760
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: omniauth-oauth
|
27
|
-
requirement: &
|
27
|
+
requirement: &2166167160 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '1.0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2166167160
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: multi_json
|
38
|
-
requirement: &
|
38
|
+
requirement: &2166164200 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 1.3.6
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2166164200
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &2166159020 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '2.7'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2166159020
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rack-test
|
60
|
-
requirement: &
|
60
|
+
requirement: &2166157120 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *2166157120
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: simplecov
|
71
|
-
requirement: &
|
71
|
+
requirement: &2166155100 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *2166155100
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: webmock
|
82
|
-
requirement: &
|
82
|
+
requirement: &2166153360 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,7 +87,7 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *2166153360
|
91
91
|
description: OmniAuth strategy for Desk.com
|
92
92
|
email:
|
93
93
|
- tstachl@salesforce.com
|
@@ -123,7 +123,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
123
123
|
version: '0'
|
124
124
|
segments:
|
125
125
|
- 0
|
126
|
-
hash:
|
126
|
+
hash: 2082149953503729504
|
127
127
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
128
|
none: false
|
129
129
|
requirements:
|
@@ -132,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
132
|
version: '0'
|
133
133
|
segments:
|
134
134
|
- 0
|
135
|
-
hash:
|
135
|
+
hash: 2082149953503729504
|
136
136
|
requirements: []
|
137
137
|
rubyforge_project: omniauth-desk
|
138
138
|
rubygems_version: 1.8.10
|