omniauth-g5 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 11b40e7d7c3dc0c0dfd4d01586f52f0d29ac1b62
4
- data.tar.gz: fd85bdb45987fe74f697f47a98257e248b28512f
3
+ metadata.gz: 3c725fd3953602794351ab2800883220afc39466
4
+ data.tar.gz: 8fc1bede6057617700b3f76643257af2cb676e38
5
5
  SHA512:
6
- metadata.gz: e1101ff8051b3e386ae8bb30da99adc6691fc7558dd8f8c97f2874c6d827566f586faf42784ae422ed7240737af57dd2ad565dcefc4f6ebee23b1dcec59dfe55
7
- data.tar.gz: 34b9d4c94b0e656ddf3e6aa4a99308e3ad609e33fec5eab63977b188ad1108d832c7cffccda04d1b290699dead53520b4d01ca98afbea380bbd363f5ef66c6a7
6
+ metadata.gz: e6c228bccc9af1fb6a4073d1370e51d0379f481efc6293994f0b8909a20523998d129cac00bbe777667dab694548f859735c742d903cb44b34928d5129b8ea67
7
+ data.tar.gz: e44cbdc3809ba2f2f513ecae13d4ebe6e78ae5a5a95155b1a9b90e7935ec0e4deacd64c7d31ada5a8af2403b330aaf63d300ac7efea88420cfacf536d6d337e3
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.1.0
1
+ 2.2.0
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1.2
5
+ - 2.1.5
6
+ - 2.2.0
7
+ - 2.2.2
8
+ script:
9
+ - bundle exec rspec spec
data/CHANGELOG.md CHANGED
@@ -1,10 +1,16 @@
1
- # v0.1.0 (2014-03-12)
1
+ ## v0.2.0 (2015-05-20)
2
+
3
+ * Added new fields to auth hash for user name, phone, title, and organization.
4
+ * Added user roles to the auth hash
5
+ ([#8](https://github.com/G5/omniauth-g5/pull/8))
6
+
7
+ ## v0.1.0 (2014-03-12)
2
8
 
3
9
  * Moved `rake g5:export_users` task to
4
10
  [devise_g5_authenticatable](https://github.com/G5/devise_g5_authenticatable)
5
11
  * First open source release to [RubyGems](https://rubygems.org)
6
12
 
7
- # v0.0.2 (2013-11-06)
13
+ ## v0.0.2 (2013-11-06)
8
14
 
9
15
  * Changed `rake g5:export_users` task to read default argument values
10
16
  from environment variables:
@@ -19,6 +25,6 @@
19
25
  * Renamed any references to the client callback URL to redirect URI, to
20
26
  maintain terminology consistent with the OAuth 2.0 specification.
21
27
 
22
- # v0.0.1 (2013-07-25)
28
+ ## v0.0.1 (2013-07-25)
23
29
 
24
30
  * Initial release
data/README.md CHANGED
@@ -8,7 +8,7 @@ This is the [OmniAuth][omniauth] strategy for authenticating to G5 via
8
8
 
9
9
  ## Current version
10
10
 
11
- 0.1.0
11
+ 0.2.0
12
12
 
13
13
  ## Requirements
14
14
 
@@ -36,6 +36,8 @@ $ gem install omniauth-g5
36
36
 
37
37
  ## Usage
38
38
 
39
+ ### Configuration
40
+
39
41
  The strategy must be initialized with a valid client application ID and secret
40
42
  provided by the G5 auth service. For example, to use the G5 strategy with
41
43
  [devise][devise]:
@@ -52,6 +54,70 @@ For more general information about setting up and using OmniAuth, see the
52
54
  [devise]: https://github.com/plataformatec/devise
53
55
  [omniauth-wiki]: https://github.com/intridea/omniauth/wiki
54
56
 
57
+ ### Auth Hash
58
+
59
+ After authenticating, OmniAuth returns a hash of information in the Rack
60
+ environment under the key `omniauth.auth`. The G5 OmniAuth strategy
61
+ specifically uses the following subset of the full
62
+ [auth hash schema](https://github.com/intridea/omniauth/wiki/Auth-Hash-Schema):
63
+
64
+ * `provider` - this will always be set to the symbol `:g5`
65
+ * `uid` - the unique identifier for the authenticated user
66
+ * `info` - a hash containing information about the user
67
+ * `email` - the email address of the authenticated user
68
+ * `name` - the display name for the user (concatenated first and last names,
69
+ or an empty string if no name fields have been populated)
70
+ * `first_name` - the user's first name (may be nil)
71
+ * `last_name` - the user's last name (may be nil)
72
+ * `phone` - the user's phone number (may be nil; no specific formatting is
73
+ enforced)
74
+ * `credentials` - information about the user's access token
75
+ * `token` - the access token string
76
+ * `expires` - boolean indicating whether the access token has an expiry date
77
+ (always set to true for G5)
78
+ * `expires_at` - timestamp of the expiry time
79
+ * `extra` - extra information returned from the auth server, including the raw
80
+ user data and custom fields specific to G5
81
+ * `title` - the user's job title (may be nil)
82
+ * `organization_name` - the user's organization name (may be nil). This does
83
+ not necessarily match the G5 client name. For example, it could be the name
84
+ of a department or business unit within the client's organization.
85
+ * `roles` - the array of roles assigned to the user (may be empty)
86
+ * `uid` - the unique identifier of the role on the auth server
87
+ * `name` - the name of the role in snakecase
88
+ * `raw_info` - a hash representation of the full JSON response from the G5
89
+ auth server
90
+
91
+ For example:
92
+
93
+ ```ruby
94
+ {"provider"=>:g5,
95
+ "uid"=>42,
96
+ "info"=>
97
+ {"email"=>"test.user@test.host",
98
+ "name"=>"Test User",
99
+ "first_name"=>"Test",
100
+ "last_name"=>"User",
101
+ "phone"=>"(555) 555-5555"},
102
+ "credentials"=>
103
+ {"token"=>"abc123",
104
+ "expires_at"=>1430170866,
105
+ "expires"=>true},
106
+ "extra"=>
107
+ {"raw_info"=>
108
+ {"id"=>42,
109
+ "email"=>"test.user@test.host",
110
+ "first_name"=>"Test",
111
+ "last_name"=>"User",
112
+ "phone_number"=>"(555) 555-5555",
113
+ "organization_name"=>"Test Org",
114
+ "title"=>"Tester",
115
+ "roles"=>[{"id"=>4,"name"=>"viewer"}]},
116
+ "title"=>"Tester",
117
+ "organization_name"=>"Test Org",
118
+ "roles" => [{"uid"=>4,"name"=>"viewer"}]}}
119
+ ```
120
+
55
121
  ## Authors
56
122
 
57
123
  * Maeve Revels / [@maeve](https://github.com/maeve)
@@ -1,5 +1,5 @@
1
1
  module OmniAuth
2
2
  module G5
3
- VERSION = '0.1.0'
3
+ VERSION = '0.2.0'
4
4
  end
5
5
  end
@@ -14,12 +14,33 @@ module OmniAuth
14
14
  uid { raw_info['id'] }
15
15
 
16
16
  info do
17
- {:email => raw_info['email']}
17
+ {:email => raw_info['email'],
18
+ :name => display_name,
19
+ :first_name => raw_info['first_name'],
20
+ :last_name => raw_info['last_name'],
21
+ :phone => raw_info['phone_number']}
22
+ end
23
+
24
+ extra do
25
+ {:raw_info => raw_info,
26
+ :title => raw_info['title'],
27
+ :organization_name => raw_info['organization_name'],
28
+ :roles => roles}
18
29
  end
19
30
 
20
31
  def raw_info
21
32
  @raw_info ||= access_token.get('/v1/me.json').parsed
22
33
  end
34
+
35
+ def display_name
36
+ "#{raw_info['first_name']} #{raw_info['last_name']}".strip
37
+ end
38
+
39
+ def roles
40
+ [raw_info['roles']].flatten.collect do |role|
41
+ {:name => role['name']}
42
+ end
43
+ end
23
44
  end
24
45
  end
25
46
  end
data/omniauth-g5.gemspec CHANGED
@@ -19,7 +19,8 @@ Gem::Specification.new do |gem|
19
19
 
20
20
  gem.add_dependency('omniauth-oauth2', '~> 1.1')
21
21
 
22
- gem.add_development_dependency('rspec', '~> 2.14')
22
+ gem.add_development_dependency('rspec', '~> 3.2')
23
+ gem.add_development_dependency('rspec-its')
23
24
  gem.add_development_dependency('simplecov', '~> 0.7')
24
25
  gem.add_development_dependency('codeclimate-test-reporter')
25
26
  gem.add_development_dependency('pry')
@@ -12,9 +12,9 @@ describe OmniAuth::Strategies::G5 do
12
12
  let(:access_token) { double(:access_token, :get => response) }
13
13
  let(:response) { double(:response, :parsed => parsed_response) }
14
14
  let(:parsed_response) { double(:parsed_response) }
15
- before { strategy.stub(:access_token => access_token) }
15
+ before { allow(strategy).to receive(:access_token).and_return(access_token) }
16
16
 
17
- its(:name) { should == :g5 }
17
+ its(:name) { is_expected.to eq(:g5) }
18
18
 
19
19
  it 'should have the correct client id' do
20
20
  expect(strategy.options[:client_id]).to eq(app_id)
@@ -28,9 +28,9 @@ describe OmniAuth::Strategies::G5 do
28
28
  subject(:client_options) { strategy.options.client_options }
29
29
 
30
30
  context 'with default options' do
31
- its(:site) { should == 'https://auth.g5search.com' }
32
- its(:authorize_url) { should == '/oauth/authorize' }
33
- its(:token_url) { should == '/oauth/token' }
31
+ its(:site) { is_expected.to eq('https://auth.g5search.com') }
32
+ its(:authorize_url) { is_expected.to eq('/oauth/authorize') }
33
+ its(:token_url) { is_expected.to eq('/oauth/token') }
34
34
  end
35
35
 
36
36
  context 'with partially overridden options' do
@@ -38,9 +38,9 @@ describe OmniAuth::Strategies::G5 do
38
38
  {:client_options => {:site => 'https://custom.app.com'}}
39
39
  end
40
40
 
41
- its(:site) { should == 'https://custom.app.com' }
42
- its(:authorize_url) { should == '/oauth/authorize' }
43
- its(:token_url) { should == '/oauth/token' }
41
+ its(:site) { is_expected.to eq('https://custom.app.com') }
42
+ its(:authorize_url) { is_expected.to eq('/oauth/authorize') }
43
+ its(:token_url) { is_expected.to eq('/oauth/token') }
44
44
  end
45
45
  end
46
46
 
@@ -48,11 +48,11 @@ describe OmniAuth::Strategies::G5 do
48
48
  subject(:raw_info) { strategy.raw_info }
49
49
 
50
50
  it 'should retrieve the user info from the server' do
51
- access_token.should_receive(:get).with('/v1/me.json').and_return(response)
51
+ expect(access_token).to receive(:get).with('/v1/me.json').and_return(response)
52
52
  raw_info
53
53
  end
54
54
 
55
- it { should == parsed_response }
55
+ it { is_expected.to eq(parsed_response) }
56
56
  end
57
57
 
58
58
  describe '#uid' do
@@ -61,15 +61,113 @@ describe OmniAuth::Strategies::G5 do
61
61
  {'id' => 123}
62
62
  end
63
63
 
64
- it { should == 123 }
64
+ it { is_expected.to eq(123) }
65
65
  end
66
66
 
67
67
  describe '#info' do
68
68
  subject(:info) { strategy.info }
69
69
  let(:parsed_response) do
70
- {'email' => 'test@test.com'}
70
+ {'email' => email,
71
+ 'first_name' => first_name,
72
+ 'last_name' => last_name,
73
+ 'phone_number' => phone_number}
71
74
  end
72
75
 
73
- its([:email]) { should == 'test@test.com' }
76
+ let(:email) { 'test@test.com' }
77
+ let(:first_name) { 'Test' }
78
+ let(:last_name) { 'User' }
79
+ let(:phone_number) { '(555) 555-5555' }
80
+
81
+ its([:email]) { is_expected.to eq(email) }
82
+ its([:name]) { is_expected.to eq("#{first_name} #{last_name}") }
83
+ its([:first_name]) { is_expected.to eq(first_name)}
84
+ its([:last_name]) { is_expected.to eq(last_name) }
85
+ its([:phone]) { is_expected.to eq(phone_number) }
86
+ end
87
+
88
+ describe '#extra' do
89
+ subject(:extra) { strategy.extra }
90
+ let(:parsed_response) do
91
+ {'title' => title,
92
+ 'organization_name' => org_name,
93
+ 'roles' => roles}
94
+ end
95
+
96
+ let(:title) { 'Grand Poobah' }
97
+ let(:org_name) { 'Test Org' }
98
+ let(:roles) { [{'name' => 'viewer'}] }
99
+
100
+ its([:raw_info]) { is_expected.to eq(parsed_response) }
101
+ its([:title]) { is_expected.to eq(title) }
102
+ its([:organization_name]) { is_expected.to eq(org_name) }
103
+ its([:roles]) { is_expected.to eq(strategy.roles) }
104
+ end
105
+
106
+ describe '#display_name' do
107
+ subject(:display_name) { strategy.display_name }
108
+ let(:parsed_response) do
109
+ {'first_name' => first_name,
110
+ 'last_name' => last_name}
111
+ end
112
+
113
+ let(:first_name) {}
114
+ let(:last_name) {}
115
+
116
+ context 'with first and last name' do
117
+ let(:first_name) { 'Test' }
118
+ let(:last_name) { 'User' }
119
+
120
+ it { is_expected.to eq("#{first_name} #{last_name}")}
121
+ end
122
+
123
+ context 'with first name only' do
124
+ let(:first_name) { 'Test'}
125
+
126
+ it { is_expected.to eq(first_name) }
127
+ end
128
+
129
+ context 'with last name only' do
130
+ let(:last_name) { 'User' }
131
+
132
+ it { is_expected.to eq(last_name) }
133
+ end
134
+
135
+ context 'without name fields' do
136
+ it { is_expected.to eq('') }
137
+ end
138
+ end
139
+
140
+ describe '#roles' do
141
+ subject(:roles) { strategy.roles }
142
+ let(:parsed_response) do
143
+ {'roles' => role_data}
144
+ end
145
+
146
+ context 'when roles are empty' do
147
+ let(:role_data) { [] }
148
+
149
+ it { is_expected.to be_empty }
150
+ end
151
+
152
+ context 'when there is one role' do
153
+ let(:role_data) { [{'name' => 'viewer'}] }
154
+
155
+ its(:count) { is_expected.to eq(1) }
156
+
157
+ it 'should return the role name' do
158
+ expect(roles.first[:name]).to eq(role_data.first['name'])
159
+ end
160
+ end
161
+
162
+ context 'when there are two roles' do
163
+ let(:role_data) do
164
+ [{'name' => 'super_admin'},
165
+ {'name' => 'editor'}]
166
+ end
167
+
168
+ its(:count) { is_expected.to eq(2) }
169
+ it { is_expected.to include({name: 'super_admin'}) }
170
+ it { is_expected.to include({name: 'editor'}) }
171
+ end
74
172
  end
75
173
  end
data/spec/spec_helper.rb CHANGED
@@ -4,6 +4,7 @@ SimpleCov.start 'test_frameworks'
4
4
  require 'codeclimate-test-reporter'
5
5
  CodeClimate::TestReporter.start
6
6
 
7
+ require 'rspec/its'
7
8
  require 'pry'
8
9
  require 'omniauth-g5'
9
10
 
@@ -13,7 +14,6 @@ require 'webmock/rspec'
13
14
 
14
15
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
15
16
  RSpec.configure do |config|
16
- config.treat_symbols_as_metadata_keys_with_true_values = true
17
17
  config.run_all_when_everything_filtered = true
18
18
  config.filter_run :focus
19
19
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-g5
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maeve Revels
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-12 00:00:00.000000000 Z
12
+ date: 2015-05-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: omniauth-oauth2
@@ -31,14 +31,28 @@ dependencies:
31
31
  requirements:
32
32
  - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: '2.14'
34
+ version: '3.2'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: '2.14'
41
+ version: '3.2'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec-its
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
42
56
  - !ruby/object:Gem::Dependency
43
57
  name: simplecov
44
58
  requirement: !ruby/object:Gem::Requirement
@@ -105,8 +119,8 @@ extra_rdoc_files: []
105
119
  files:
106
120
  - ".gitignore"
107
121
  - ".rspec"
108
- - ".ruby-gemset"
109
122
  - ".ruby-version"
123
+ - ".travis.yml"
110
124
  - CHANGELOG.md
111
125
  - Gemfile
112
126
  - LICENSE
@@ -138,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
152
  version: '0'
139
153
  requirements: []
140
154
  rubyforge_project:
141
- rubygems_version: 2.2.0
155
+ rubygems_version: 2.4.5
142
156
  signing_key:
143
157
  specification_version: 4
144
158
  summary: OmniAuth strategy for G5
@@ -146,4 +160,3 @@ test_files:
146
160
  - spec/omniauth/strategies/g5_spec.rb
147
161
  - spec/spec_helper.rb
148
162
  - spec/support/.gitkeep
149
- has_rdoc:
data/.ruby-gemset DELETED
@@ -1 +0,0 @@
1
- g5_omniauth