g5_authentication_client 0.3.0 → 0.4.0
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 +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +7 -0
- data/CHANGELOG.md +8 -1
- data/README.md +23 -1
- data/lib/g5_authentication_client.rb +1 -0
- data/lib/g5_authentication_client/client.rb +7 -0
- data/lib/g5_authentication_client/role.rb +13 -0
- data/lib/g5_authentication_client/user.rb +8 -1
- data/lib/g5_authentication_client/version.rb +1 -1
- data/spec/g5_authentication_client/client_spec.rb +29 -3
- data/spec/g5_authentication_client/role_spec.rb +64 -0
- data/spec/g5_authentication_client/user_spec.rb +35 -2
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f1b72b556d88ccf5d3db877677efbbd8f969c1b
|
4
|
+
data.tar.gz: 21a75a23db8b2e8106999de8e481923701fd9fad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5eb630f56608ad0dda5705d63ee64c9cba567621220c37b7459239c7755d9b4ee3c2bcb12bc36919ee05653ed8073e644773604684f784c662ac3b38a5bfb27a
|
7
|
+
data.tar.gz: b216905352a09469399fa36194e8973cca41a22cb715d810a64af6792b66d75e74469119c4cb2cfcbe325ff1d5c579c42fcf84bd69439b4cc15238ad1afafcd7
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.1.
|
1
|
+
2.1.6
|
data/.travis.yml
ADDED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## v0.4.0 (2015-05-20)
|
2
|
+
|
3
|
+
* Add `G5AuthenticationClient::Client#list_roles`, a new
|
4
|
+
`G5AuthenticationClient::Role` model, and support for retrieving/updating
|
5
|
+
roles in the user data
|
6
|
+
([#23](https://github.com/G5/g5_authentication_client/pull/23))
|
7
|
+
|
1
8
|
## v0.3.0 (2015-01-08)
|
2
9
|
|
3
10
|
* Add `G5AuthenticationClient::Client#list_users`
|
@@ -14,7 +21,7 @@
|
|
14
21
|
## v0.1.5 (2014-03-07)
|
15
22
|
|
16
23
|
* Add `allow_password_credentials` flag to determine whether client instances
|
17
|
-
|
24
|
+
will allow use of username/passwored attributes
|
18
25
|
|
19
26
|
## v0.1.4 (2014-03-06)
|
20
27
|
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@ A client library for the g5-authentication service.
|
|
4
4
|
|
5
5
|
## Current version ##
|
6
6
|
|
7
|
-
0.
|
7
|
+
0.4.0
|
8
8
|
|
9
9
|
## Requirements ##
|
10
10
|
|
@@ -206,6 +206,28 @@ auth_client.sign_out_url('https://myapp.host/callback')
|
|
206
206
|
# => "https://auth.g5search.com/users/sign_out?redirect_url=https%3A%2F%2Fmyapp.host%2Fcallback"
|
207
207
|
```
|
208
208
|
|
209
|
+
### Retrieving user roles ###
|
210
|
+
|
211
|
+
A user's assigned roles will be included automatically when you retrieve user
|
212
|
+
data via `get_user` or `list_users`.
|
213
|
+
|
214
|
+
To retrieve a list of all roles (to which you have access) in the G5 auth
|
215
|
+
service:
|
216
|
+
|
217
|
+
```ruby
|
218
|
+
auth_client = G5AuthenticationClient::Client.new(access_token: 'my_access_token')
|
219
|
+
auth_client.list_roles
|
220
|
+
# => [#<G5AuthenticationClient::Role id=3 name="editor">, #<G5AuthenticationClient::Role id=4 name="viewer">, ...]
|
221
|
+
```
|
222
|
+
|
223
|
+
To retrieve information about a particular role:
|
224
|
+
|
225
|
+
```ruby
|
226
|
+
auth_client = G5AuthenticationClient::Client.new(access_token: 'my_access_token')
|
227
|
+
auth_client.get_role(4)
|
228
|
+
# => #<G5AuthenticationClient::Role id=4 name="viewer">
|
229
|
+
```
|
230
|
+
|
209
231
|
## Examples ##
|
210
232
|
|
211
233
|
These examples assume that you have already registered your client application
|
@@ -3,6 +3,7 @@ require 'g5_authentication_client/version'
|
|
3
3
|
require 'g5_authentication_client/configuration'
|
4
4
|
require 'g5_authentication_client/user'
|
5
5
|
require 'g5_authentication_client/token_info'
|
6
|
+
require 'g5_authentication_client/role'
|
6
7
|
|
7
8
|
module G5AuthenticationClient
|
8
9
|
extend Configuration
|
@@ -176,6 +176,13 @@ module G5AuthenticationClient
|
|
176
176
|
response.parsed.collect { |parsed_user| User.new(parsed_user) }
|
177
177
|
end
|
178
178
|
|
179
|
+
# Return all user roles from the remote service
|
180
|
+
# @return [Array<G5AuthenticationClient::Role>]
|
181
|
+
def list_roles
|
182
|
+
response = oauth_access_token.get('/v1/roles')
|
183
|
+
response.parsed.collect { |parsed_role| Role.new(parsed_role) }
|
184
|
+
end
|
185
|
+
|
179
186
|
private
|
180
187
|
|
181
188
|
def user_hash(h)
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'modelish'
|
2
|
+
|
3
|
+
module G5AuthenticationClient
|
4
|
+
# G5 Authentication user role info
|
5
|
+
class Role < Modelish::Base
|
6
|
+
ignore_unknown_properties!
|
7
|
+
|
8
|
+
# @!attribute [rw] name
|
9
|
+
# @return [String]
|
10
|
+
# The name associated with this user role
|
11
|
+
property :name, type: String, required: true
|
12
|
+
end
|
13
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'modelish'
|
2
|
+
require 'g5_authentication_client/role'
|
2
3
|
|
3
4
|
module G5AuthenticationClient
|
4
5
|
|
@@ -50,10 +51,16 @@ module G5AuthenticationClient
|
|
50
51
|
# The user's phone number. Not required to create a user.
|
51
52
|
property :phone_number, type: String
|
52
53
|
|
54
|
+
# @!attribute [rw] roles
|
55
|
+
# @return [Array<G5AuthenticationClient::Role>]
|
56
|
+
# The user's roles. Not required to create a user.
|
57
|
+
property :roles, default: [],
|
58
|
+
type: proc { |val| val.map { |r| Role.new(r) } },
|
59
|
+
validator: proc { |val| "User roles must be valid" if val && val.detect { |r| !r.valid? } }
|
60
|
+
|
53
61
|
def validate_for_create!
|
54
62
|
validate!
|
55
63
|
raise ArgumentError.new("Password required for new user.") unless !password.nil?
|
56
64
|
end
|
57
|
-
|
58
65
|
end
|
59
66
|
end
|
@@ -42,7 +42,8 @@ describe G5AuthenticationClient::Client do
|
|
42
42
|
let(:new_user_options) do
|
43
43
|
{email: email,
|
44
44
|
password: "#{password}x",
|
45
|
-
id: user_id
|
45
|
+
id: user_id,
|
46
|
+
roles: [{name: role_name}]}
|
46
47
|
end
|
47
48
|
|
48
49
|
let(:new_user_request) do
|
@@ -54,14 +55,17 @@ describe G5AuthenticationClient::Client do
|
|
54
55
|
"password"=>"#{password}x",
|
55
56
|
"password_confirmation"=>"",
|
56
57
|
"phone_number"=>"",
|
57
|
-
"title"=>""
|
58
|
+
"title"=>"",
|
59
|
+
"roles"=>["name"=>role_name]
|
58
60
|
}
|
59
61
|
end
|
60
62
|
|
61
63
|
let(:email){'foo@blah.com'}
|
62
64
|
let(:password){'mybigtestpasswored'}
|
63
65
|
let(:user_id){1}
|
64
|
-
let(:
|
66
|
+
let(:role_name) { 'my_role' }
|
67
|
+
let(:returned_user){{id: user_id,email: email,roles:[returned_role]}}
|
68
|
+
let(:returned_role) { {'name' => role_name} }
|
65
69
|
|
66
70
|
context 'with default configuration' do
|
67
71
|
subject(:client) { G5AuthenticationClient::Client.new }
|
@@ -444,4 +448,26 @@ describe G5AuthenticationClient::Client do
|
|
444
448
|
it_should_behave_like 'an oauth protected resource', G5AuthenticationClient::User
|
445
449
|
end
|
446
450
|
end
|
451
|
+
|
452
|
+
describe '#list_roles' do
|
453
|
+
subject(:list_roles) { client.list_roles }
|
454
|
+
|
455
|
+
before do
|
456
|
+
stub_request(:get, /#{endpoint}\/v1\/roles/).
|
457
|
+
with(headers: {'Authorization' => auth_header_value}).
|
458
|
+
to_return(status: 200,
|
459
|
+
body: [returned_role].to_json,
|
460
|
+
headers: {'Content-Type' => 'application/json'})
|
461
|
+
end
|
462
|
+
|
463
|
+
it 'should return one role' do
|
464
|
+
expect(list_roles.size).to eq(1)
|
465
|
+
end
|
466
|
+
|
467
|
+
describe 'the first role' do
|
468
|
+
subject(:role) { list_roles.first }
|
469
|
+
|
470
|
+
it_should_behave_like 'an oauth protected resource', G5AuthenticationClient::Role
|
471
|
+
end
|
472
|
+
end
|
447
473
|
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe G5AuthenticationClient::Role do
|
4
|
+
subject(:role) { G5AuthenticationClient::Role.new(attributes) }
|
5
|
+
|
6
|
+
let(:attributes) { {name: name} }
|
7
|
+
let(:name) { 'awesome_role' }
|
8
|
+
|
9
|
+
context 'with default initialization' do
|
10
|
+
let(:attributes) {}
|
11
|
+
|
12
|
+
it 'should have a nil name' do
|
13
|
+
expect(role.name).to be_nil
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'with full initialization' do
|
18
|
+
it 'should have the correct name' do
|
19
|
+
expect(role.name).to eq(name)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'when attributes include unknown properties' do
|
24
|
+
let(:attributes) { {name: name, resource: 'Application'} }
|
25
|
+
|
26
|
+
it 'should not raise an error' do
|
27
|
+
expect { role }.to_not raise_error
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should have the correct name' do
|
31
|
+
expect(role.name).to eq(name)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should ignore the unknown attribute' do
|
35
|
+
expect(role).to_not respond_to(:resource)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#validate!' do
|
40
|
+
subject(:validate!) { role.validate! }
|
41
|
+
|
42
|
+
context 'when all attributes are set' do
|
43
|
+
it 'should not raise an error' do
|
44
|
+
expect { validate! }.to_not raise_error
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'when name is not set' do
|
49
|
+
let(:name) {}
|
50
|
+
|
51
|
+
it 'should raise an error' do
|
52
|
+
expect { validate! }.to raise_error
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '#to_hash' do
|
58
|
+
subject(:hash) { role.to_hash }
|
59
|
+
|
60
|
+
it 'should have the correct name' do
|
61
|
+
expect(hash['name']).to eq(name)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -12,7 +12,8 @@ describe G5AuthenticationClient::User do
|
|
12
12
|
last_name: last_name,
|
13
13
|
title: title,
|
14
14
|
organization_name: organization_name,
|
15
|
-
phone_number: phone_number
|
15
|
+
phone_number: phone_number,
|
16
|
+
roles: [{name: role_name}]
|
16
17
|
}
|
17
18
|
end
|
18
19
|
|
@@ -25,6 +26,7 @@ describe G5AuthenticationClient::User do
|
|
25
26
|
let(:organization_name) { 'Things, Inc.' }
|
26
27
|
let(:phone_number) { '8675309123' }
|
27
28
|
let(:title) { 'Developer' }
|
29
|
+
let(:role_name) { 'Editor' }
|
28
30
|
|
29
31
|
context 'with default initialization' do
|
30
32
|
let(:attributes){}
|
@@ -44,10 +46,13 @@ describe G5AuthenticationClient::User do
|
|
44
46
|
it 'should have nil password_confirmation' do
|
45
47
|
expect(user.password_confirmation).to be_nil
|
46
48
|
end
|
49
|
+
|
50
|
+
it 'should have empty roles' do
|
51
|
+
expect(user.roles).to be_empty
|
52
|
+
end
|
47
53
|
end
|
48
54
|
|
49
55
|
context 'with full initialization' do
|
50
|
-
|
51
56
|
it 'should have correct email' do
|
52
57
|
expect(user.email).to eq(email)
|
53
58
|
end
|
@@ -83,6 +88,14 @@ describe G5AuthenticationClient::User do
|
|
83
88
|
it 'should have correct organization_name' do
|
84
89
|
expect(user.organization_name).to eq(organization_name)
|
85
90
|
end
|
91
|
+
|
92
|
+
it 'should have the correct number of roles' do
|
93
|
+
expect(user.roles.size).to eq(attributes[:roles].size)
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'should have the correct role name' do
|
97
|
+
expect(user.roles.first.name).to eq(role_name)
|
98
|
+
end
|
86
99
|
end
|
87
100
|
|
88
101
|
describe '#validate!' do
|
@@ -159,6 +172,22 @@ describe G5AuthenticationClient::User do
|
|
159
172
|
expect { validate! }.to_not raise_error
|
160
173
|
end
|
161
174
|
end
|
175
|
+
|
176
|
+
context 'without roles' do
|
177
|
+
let(:roles) {}
|
178
|
+
|
179
|
+
it 'should not raise an error' do
|
180
|
+
expect { validate! }.to_not raise_error
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
context 'with invalid roles' do
|
185
|
+
let(:role_name) {}
|
186
|
+
|
187
|
+
it 'should raise an error' do
|
188
|
+
expect { validate! }.to raise_error
|
189
|
+
end
|
190
|
+
end
|
162
191
|
end
|
163
192
|
|
164
193
|
describe '#validate_for_create!' do
|
@@ -212,5 +241,9 @@ describe G5AuthenticationClient::User do
|
|
212
241
|
it 'should have an id' do
|
213
242
|
expect(to_hash['id']).to eq(id)
|
214
243
|
end
|
244
|
+
|
245
|
+
it 'should have roles' do
|
246
|
+
expect(to_hash['roles']).to eq([{'name' => role_name}])
|
247
|
+
end
|
215
248
|
end
|
216
249
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: g5_authentication_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob Revels
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-05-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: modelish
|
@@ -204,6 +204,7 @@ files:
|
|
204
204
|
- ".gitignore"
|
205
205
|
- ".rspec"
|
206
206
|
- ".ruby-version"
|
207
|
+
- ".travis.yml"
|
207
208
|
- CHANGELOG.md
|
208
209
|
- Gemfile
|
209
210
|
- LICENSE
|
@@ -213,11 +214,13 @@ files:
|
|
213
214
|
- lib/g5_authentication_client.rb
|
214
215
|
- lib/g5_authentication_client/client.rb
|
215
216
|
- lib/g5_authentication_client/configuration.rb
|
217
|
+
- lib/g5_authentication_client/role.rb
|
216
218
|
- lib/g5_authentication_client/token_info.rb
|
217
219
|
- lib/g5_authentication_client/user.rb
|
218
220
|
- lib/g5_authentication_client/version.rb
|
219
221
|
- spec/g5_authentication_client/client_spec.rb
|
220
222
|
- spec/g5_authentication_client/configuration_spec.rb
|
223
|
+
- spec/g5_authentication_client/role_spec.rb
|
221
224
|
- spec/g5_authentication_client/token_info_spec.rb
|
222
225
|
- spec/g5_authentication_client/user_spec.rb
|
223
226
|
- spec/g5_authentication_client_spec.rb
|
@@ -243,7 +246,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
243
246
|
version: '0'
|
244
247
|
requirements: []
|
245
248
|
rubyforge_project: g5_authentication_client
|
246
|
-
rubygems_version: 2.2.
|
249
|
+
rubygems_version: 2.2.3
|
247
250
|
signing_key:
|
248
251
|
specification_version: 4
|
249
252
|
summary: Client for the G5 Auth service
|