omniauth-granicus 1.1.3 → 1.1.4

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.
@@ -1,5 +1,5 @@
1
1
  module OmniAuth
2
2
  module GranicusAdmin
3
- VERSION = "1.1.3"
3
+ VERSION = "1.1.4"
4
4
  end
5
5
  end
@@ -6,14 +6,12 @@ module OmniAuth
6
6
  module Strategies
7
7
  class GranicusAdmin < OmniAuth::Strategies::OAuth2
8
8
  class NoAuthorizationCodeError < StandardError; end
9
- class InvalidTokenHostError < StandardError; end
10
9
 
11
10
  DEFAULT_SCOPE = ''
12
11
 
13
12
  option :name, 'granicus_admin'
14
13
 
15
14
  option :client_options, {
16
- :site => 'https://citizen.dev.granicus.com',
17
15
  :token_url => '/auth/oauth/token',
18
16
  :authorize_url => '/auth/oauth/authorize',
19
17
  :token_method => :get,
@@ -25,7 +23,7 @@ module OmniAuth
25
23
  :parse => :json
26
24
  }
27
25
 
28
- option :authorize_options, [:scope, :host]
26
+ option :authorize_options, [ :scope ]
29
27
 
30
28
  uid { raw_info['userid'] }
31
29
 
@@ -51,10 +49,16 @@ module OmniAuth
51
49
  })
52
50
  end
53
51
 
52
+ def client
53
+ options.client_options[:site] = "https://#{options.host}"
54
+
55
+ super
56
+ end
57
+
54
58
  def raw_info
55
59
  @raw_info ||= access_token.get('/auth/identity/me').parsed
56
60
  @raw_info['name'] ||= @raw_info['username']
57
- @raw_info['email'] ||= "#{@raw_info['username']}@#{request.params['host']}"
61
+ @raw_info['email'] ||= "#{@raw_info['username']}@#{options.host}"
58
62
 
59
63
  @raw_info
60
64
  end
@@ -64,28 +68,15 @@ module OmniAuth
64
68
  token.options.merge!(access_token_options)
65
69
  end
66
70
  end
67
-
68
- ##
69
- # Add the host param to the callback url so that we know where to go for our token
70
- #
71
- def callback_url
72
- full_host + script_name + callback_path + "?host=#{request.params['host']}"
73
- end
74
71
 
75
72
  ##
76
73
  # Implement multi-tenancy support in the callback phase with a check to ensure we are still
77
74
  # talking to the right domain to prevent hijacking of the oauth token process
78
75
  #
79
76
  def callback_phase
80
- if !request.params['host'].nil? && request.params['host'] =~ /\.granicus\.com$/
81
- options.client_options[:site] = "https://#{request.params['host']}"
82
- else
83
- raise InvalidTokenHostError.new
84
- end
77
+ options.client_options[:site] = "https://#{options.host}"
85
78
 
86
79
  super
87
- rescue InvalidTokenHostError => e
88
- fail!(:invalid_token_host, e)
89
80
  end
90
81
 
91
82
  def access_token_options
@@ -97,15 +88,12 @@ module OmniAuth
97
88
  # you need to set them dynamically. You can also set these options
98
89
  # in the OmniAuth config :authorize_params option.
99
90
  #
100
- # /auth/granicus_admin?host=sacramento.granicus.com
101
91
  #
102
92
  def authorize_params
103
93
  super.tap do |params|
104
- %w[host scope].each { |v| params[v.to_sym] = request.params[v] if request.params[v] }
94
+ %w[scope].each { |v| params[v.to_sym] = request.params[v] if request.params[v] }
105
95
  params[:scope] ||= DEFAULT_SCOPE
106
- if !params[:host].nil?
107
- options.client_options[:site] = "https://#{params[:host]}"
108
- end
96
+ params[:host] = options.host
109
97
  end
110
98
  end
111
99
 
@@ -9,7 +9,8 @@ describe OmniAuth::Strategies::GranicusAdmin do
9
9
  @request.stub(:params) { {} }
10
10
  @request.stub(:cookies) { {} }
11
11
  @request.stub(:env) { {} }
12
-
12
+ @options = { :host => 'citizen.dev.granicus.com' }
13
+
13
14
  @client_id = '123'
14
15
  @client_secret = '53cr3tz'
15
16
  end
@@ -33,6 +34,7 @@ describe OmniAuth::Strategies::GranicusAdmin do
33
34
  end
34
35
 
35
36
  it 'has correct token url' do
37
+ @options = { :host => 'citizen.dev.granicus.com' }
36
38
  subject.client.options[:token_url].should eq('/auth/oauth/token')
37
39
  end
38
40
  end
@@ -41,18 +43,16 @@ describe OmniAuth::Strategies::GranicusAdmin do
41
43
  it "returns the default callback url" do
42
44
  url_base = 'http://auth.request.com'
43
45
  @request.stub(:url) { "#{url_base}/some/page" }
44
- @request.stub(:params) { { 'host' => 'dev.dev.granicus.com' }}
45
46
  subject.stub(:script_name) { '' } # as not to depend on Rack env
46
- subject.callback_url.should eq("#{url_base}/auth/granicus_admin/callback?host=dev.dev.granicus.com")
47
+ subject.callback_url.should eq("#{url_base}/auth/granicus_admin/callback?host=citizen.dev.granicus.com")
47
48
  end
48
49
 
49
50
  it "returns path from callback_path option" do
50
- @options = { :callback_path => "/auth/FB/done"}
51
+ @options[:callback_path] = "/auth/FB/done"
51
52
  url_base = 'http://auth.request.com'
52
53
  @request.stub(:url) { "#{url_base}/page/path" }
53
- @request.stub(:params) { { 'host' => 'dev.dev.granicus.com' }}
54
54
  subject.stub(:script_name) { '' } # as not to depend on Rack env
55
- subject.callback_url.should eq("#{url_base}/auth/FB/done?host=dev.dev.granicus.com")
55
+ subject.callback_url.should eq("#{url_base}/auth/FB/done?host=citizen.dev.granicus.com")
56
56
  end
57
57
 
58
58
  end
@@ -64,10 +64,9 @@ describe OmniAuth::Strategies::GranicusAdmin do
64
64
  end
65
65
 
66
66
  it 'changes site to site defined by host param in request when present' do
67
- @request.stub(:params) { { 'host' => 'dev.dev.granicus.com' } }
68
67
  subject.authorize_params.should be_a(Hash)
69
- subject.authorize_params[:host].should eq('dev.dev.granicus.com')
70
- subject.client.site.should eq('https://dev.dev.granicus.com')
68
+ subject.authorize_params[:host].should eq('citizen.dev.granicus.com')
69
+ subject.client.site.should eq('https://citizen.dev.granicus.com')
71
70
  end
72
71
 
73
72
  it 'overrides default scope with parameter passed from request' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-granicus
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.4
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-04-26 00:00:00.000000000Z
12
+ date: 2012-04-27 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: omniauth-oauth2
16
- requirement: &2152544460 !ruby/object:Gem::Requirement
16
+ requirement: &2152507980 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2152544460
24
+ version_requirements: *2152507980
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &2152543220 !ruby/object:Gem::Requirement
27
+ requirement: &2152507080 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 2.7.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2152543220
35
+ version_requirements: *2152507080
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &2152540540 !ruby/object:Gem::Requirement
38
+ requirement: &2152502600 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2152540540
46
+ version_requirements: *2152502600
47
47
  description:
48
48
  email:
49
49
  - javier@granicus.com