omniauth-desk 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cb5c9d6a35eec35c54d835aa245a32b592d95d88
4
- data.tar.gz: a32777466a42a486ca39f37232f9b90432547b65
3
+ metadata.gz: 78ae51cd756cb4ce1389d03aadad0ff24920bdbc
4
+ data.tar.gz: b5299b0606bbf76e9e888952da4732d751a1a24c
5
5
  SHA512:
6
- metadata.gz: 386f5c66038ce6945e2dc79d883c68ceb14ecf21a8166a60cb84423c4a618df20b93219c4aa7329d65b330bf6d2ed91867e5cc600164f2b40d4bf349177eb383
7
- data.tar.gz: 74ef9e42d60c969c47e0ce50e955466a65ab07036f4a6e9991880c90fe6e022cffc21fa6f8afd1da9c429595e313224b059395dfe1d846c77f62ef8f5d2bc4eb
6
+ metadata.gz: 737efb1f76b076c0b84d997105b8eff2e55008be070d3972fcfaae73545d108844d8bf391afbb07199b63e5e20c989bef56b1266fa2da84a236285dd194d8abd
7
+ data.tar.gz: cca26acc58fa1cd48a543d2726657c5570e4ca05afa708f44ed7c46b0a1cb38f8612ac0e5906848477cd057a01a90cbebea49e125330f72e436fcb45fcb8ed02
@@ -15,11 +15,11 @@ module OmniAuth
15
15
  :access_token_path => '/oauth/access_token',
16
16
  }
17
17
 
18
- uid {
18
+ uid {
19
19
  user_info['id']
20
20
  }
21
-
22
- info do
21
+
22
+ info do
23
23
  {
24
24
  :name => user_info['name'],
25
25
  :name_public => user_info['name_public'],
@@ -29,14 +29,14 @@ module OmniAuth
29
29
  :site => session[:site]
30
30
  }
31
31
  end
32
-
32
+
33
33
  extra do
34
34
  {
35
35
  :raw_info => raw_info
36
36
  }
37
37
  end
38
38
 
39
- # Return info gathered from the verify_credentials API call
39
+ # Return info gathered from the verify_credentials API call
40
40
  def raw_info
41
41
  @raw_info ||= MultiJson.decode(access_token.get('/api/v2/users/me').body) if access_token
42
42
  rescue ::Errno::ETIMEDOUT
@@ -47,38 +47,36 @@ module OmniAuth
47
47
  def user_info
48
48
  @user_info ||= raw_info.nil? ? {} : raw_info
49
49
  end
50
-
50
+
51
51
  def identifier
52
52
  session[:site] = options.client_options.site = options.site || validate_site(request.params[options.site_param.to_s])
53
53
  session[:site] = options.client_options.site = nil if options.client_options.site == ''
54
54
  options.client_options.site
55
55
  end
56
-
56
+
57
57
  def uri?(uri)
58
58
  uri = URI.parse(uri)
59
59
  uri.scheme == 'https'
60
- rescue URI::BadURIError
61
- false
62
- rescue URI::InvalidURIError
63
- false
64
60
  end
65
-
61
+
66
62
  def validate_site(site)
67
63
  if site and site != ''
68
64
  uri?(site) ? site : "https://#{site}.desk.com"
69
65
  end
70
66
  end
71
-
67
+
72
68
  def get_identifier
73
- f = OmniAuth::Form.new :title => 'Desk.com Authorization'
74
- f.text_field 'Desk.com Site', options.site_param.to_s
69
+ f = OmniAuth::Form.new title: 'Desk.com Authorization'
70
+ f.text_field 'Site', options.site_param.to_s
75
71
  f.html '<p><strong>Hint:</strong> https://YOURSITE.desk.com'
76
72
  f.button 'Login'
77
73
  f.to_response
78
74
  end
79
-
75
+
80
76
  def request_phase
81
77
  identifier ? super : get_identifier
78
+ rescue ::OAuth::Unauthorized => err
79
+ fail!(:unathorized, err)
82
80
  end
83
81
 
84
82
  def callback_phase
@@ -87,4 +85,4 @@ module OmniAuth
87
85
  end
88
86
  end
89
87
  end
90
- end
88
+ end
@@ -1,5 +1,5 @@
1
1
  module OmniAuth
2
2
  module Desk
3
- VERSION = "0.1.6"
3
+ VERSION = "0.1.7"
4
4
  end
5
- end
5
+ end
@@ -17,13 +17,13 @@ Gem::Specification.new do |s|
17
17
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
-
20
+
21
21
  s.add_runtime_dependency 'omniauth', '>= 1.0'
22
22
  s.add_runtime_dependency 'omniauth-oauth', '>= 1.0'
23
23
  s.add_runtime_dependency 'multi_json', '>= 1.3.6'
24
-
25
- s.add_development_dependency 'rspec', '~> 2.7'
24
+
25
+ s.add_development_dependency 'rspec', '~> 3.5'
26
26
  s.add_development_dependency 'rack-test'
27
27
  s.add_development_dependency 'simplecov'
28
28
  s.add_development_dependency 'webmock'
29
- end
29
+ end
@@ -4,90 +4,102 @@ describe OmniAuth::Strategies::Desk, :type => :strategy do
4
4
  def app
5
5
  strat = OmniAuth::Strategies::Desk
6
6
  Rack::Builder.new {
7
- use Rack::Session::Cookie
7
+ use Rack::Session::Cookie, :secret => "MY_SECRET"
8
8
  use strat
9
9
  run lambda {|env| [404, {'Content-Type' => 'text/plain'}, [nil || env.key?('omniauth.auth').to_s]] }
10
10
  }.to_app
11
11
  end
12
-
12
+
13
13
  describe '/auth/desk without a site URL' do
14
14
  before do
15
15
  get '/auth/desk'
16
16
  end
17
-
17
+
18
18
  it 'should respond with OK' do
19
- last_response.should be_ok
19
+ expect(last_response)
20
20
  end
21
-
21
+
22
22
  it 'should respond with HTML' do
23
- last_response.content_type.should == 'text/html'
23
+ expect(last_response.content_type).to eq('text/html')
24
24
  end
25
25
 
26
26
  it 'should render an identifier URL input' do
27
- last_response.body.should =~ %r{<input[^>]*desk_site}
27
+ expect(last_response.body).to match(/<input[^>]*desk_site/)
28
28
  end
29
29
  end
30
30
 
31
31
  describe '/auth/desk with a site name' do
32
32
  before do
33
33
  @stub_devel = stub_request(:post, "https://devel.desk.com/oauth/request_token")
34
- .to_return(:status => 200, :body => 'oauth_token=&oauth_token_secret=')
35
- post '/auth/desk', { :desk_site => 'devel' }
34
+ .to_return(status: 200, body: 'oauth_token=&oauth_token_secret=')
35
+ post '/auth/desk', desk_site: 'devel'
36
36
  end
37
37
 
38
38
  it 'should have been requested' do
39
- @stub_devel.should have_been_requested
39
+ expect(@stub_devel).to have_been_requested
40
40
  end
41
41
  end
42
-
42
+
43
43
  describe '/auth/desk with a custom site name' do
44
44
  before do
45
45
  @stub_devel = stub_request(:post, "https://devel.desk.com/oauth/request_token")
46
- .to_return(:status => 200, :body => 'oauth_token=&oauth_token_secret=')
47
- post '/auth/desk', { :desk_site => 'https://devel.desk.com' }
46
+ .to_return(status: 200, body: 'oauth_token=&oauth_token_secret=')
47
+ post '/auth/desk', desk_site: 'https://devel.desk.com'
48
48
  end
49
-
49
+
50
50
  it 'should have been requested' do
51
- @stub_devel.should have_been_requested
51
+ expect(@stub_devel).to have_been_requested
52
52
  end
53
53
  end
54
-
54
+
55
55
  describe 'followed by /auth/desk/callback' do
56
56
  context 'successful' do
57
- it 'should set provider to desk'
57
+ before do
58
+ stub_request(:post, "https://devel.desk.com/oauth/request_token")
59
+ .to_return(status: 200, body: 'oauth_token=&oauth_token_secret=')
60
+
61
+ post '/auth/desk', desk_site: 'https://devel.desk.com'
62
+
63
+ @access_token = stub_request(:post, "https://devel.desk.com/oauth/access_token")
64
+ .to_return(status: 200, body: "oauth_token=6253282-eWudHldSbIaelX7swmsiHImEL4KinwaGloHANdrY&oauth_token_secret=2EEfA6BG3ly3sR3RjE0IBSnlQu4ZrUzPiYKmrkVU&user_id=6253282&screen_name=twitterapi")
65
+
66
+ @api_request = stub_request(:get, "https://devel.desk.com/api/v2/users/me")
67
+ .to_return(status: 200, body: '{"id":1,"name":"John Doe","public_name":"John Doe","email":"john@acme.com","level":"agent","created_at":"2015-05-11T14:40:01Z","updated_at":"2016-05-04T14:40:01Z","current_login_at":"2016-05-10T14:40:01Z","last_login_at":"2016-05-04T14:40:01Z","_links":{"self":{"href":"/api/v2/users/1","class":"user"},"preferences":{"href":"/api/v2/users/1/preferences","class":"user_preference"},"macros":{"href":"/api/v2/users/1/macros","class":"macro"},"filters":{"href":"/api/v2/users/1/filters","class":"filter"},"integration_urls":{"href":"/api/v2/users/1/integration_urls","class":"integration_url"},"groups":{"href":"/api/v2/users/1/groups","class":"group"},"searches":{"href":"/api/v2/users/1/searches","class":"search"}}}')
68
+
69
+ get '/auth/desk/callback?code=aWekysIEeqM9PiT2hEfm0Cnr6MoLIfwWyRJcqOqHdF8f9INokharAS09ia7UNP6RiVScerfhc4w%3D%3D'
70
+ end
71
+
72
+ it 'should request the access token' do
73
+ expect(@access_token).to have_been_requested
74
+ end
75
+
76
+ it 'should request the user data' do
77
+ expect(@api_request).to have_been_requested
78
+ end
58
79
  end
59
-
80
+
60
81
  context 'unsuccessful' do
61
82
  before do
62
83
  get '/auth/desk/callback'
63
84
  end
64
-
85
+
65
86
  it 'should be redirected to failure' do
66
- last_response.should be_redirect
67
- last_response.headers['Location'].should =~ %r{failure}
87
+ expect(last_response).to be_redirect
88
+ expect(last_response.headers['Location']).to match(/failure/)
68
89
  end
69
90
  end
70
91
  end
71
92
 
72
- # context "client options" do
73
- # it 'should have correct name' do
74
- # subject.options.name.should eq("desk")
75
- # end
76
- #
77
- # it 'should have correct authorize path' do
78
- # subject.options.client_options.authorize_path.should eq('/oauth/authorize')
79
- # end
80
- #
81
- # it 'should have correct request token path' do
82
- # subject.options.client_options.request_token_path.should eq('/oauth/request_token')
83
- # end
84
- #
85
- # it 'should have correct access token path' do
86
- # subject.options.client_options.access_token_path.should eq('/oauth/access_token')
87
- # end
88
- #
89
- # it 'should have an empty user_info' do
90
- # subject.user_info.should eq({})
91
- # end
92
- # end
93
- end
93
+ context 'invalid site' do
94
+ before do
95
+ stub_request(:post, "https://thisdoesnotexist.desk.com/oauth/request_token")
96
+ .to_return(status: 403, body: 'oauth_token=&oauth_token_secret=')
97
+ post '/auth/desk', desk_site: 'https://thisdoesnotexist.desk.com'
98
+ end
99
+
100
+ it 'should be redirected to failure' do
101
+ expect(last_response).to be_redirect
102
+ expect(last_response.headers['Location']).to match(/failure/)
103
+ end
104
+ end
105
+ end
data/spec/spec_helper.rb CHANGED
@@ -12,4 +12,4 @@ RSpec.configure do |config|
12
12
  config.include WebMock::API
13
13
  config.include Rack::Test::Methods
14
14
  config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
15
- end
15
+ end
metadata CHANGED
@@ -1,111 +1,111 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-desk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Stachl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-13 00:00:00.000000000 Z
11
+ date: 2016-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: omniauth
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: omniauth-oauth
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: multi_json
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: 1.3.6
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: 1.3.6
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '2.7'
61
+ version: '3.5'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '2.7'
68
+ version: '3.5'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rack-test
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ! '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ! '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: simplecov
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ! '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ! '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: webmock
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ! '>='
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ! '>='
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  description: OmniAuth strategy for Desk.com
@@ -115,9 +115,9 @@ executables: []
115
115
  extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
- - .gitignore
119
- - .rspec
120
- - .rvmrc
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".rvmrc"
121
121
  - Gemfile
122
122
  - LICENSE
123
123
  - README.md
@@ -137,17 +137,17 @@ require_paths:
137
137
  - lib
138
138
  required_ruby_version: !ruby/object:Gem::Requirement
139
139
  requirements:
140
- - - ! '>='
140
+ - - ">="
141
141
  - !ruby/object:Gem::Version
142
142
  version: '0'
143
143
  required_rubygems_version: !ruby/object:Gem::Requirement
144
144
  requirements:
145
- - - ! '>='
145
+ - - ">="
146
146
  - !ruby/object:Gem::Version
147
147
  version: '0'
148
148
  requirements: []
149
149
  rubyforge_project: omniauth-desk
150
- rubygems_version: 2.2.2
150
+ rubygems_version: 2.5.1
151
151
  signing_key:
152
152
  specification_version: 4
153
153
  summary: OmniAuth strategy for Desk.com