nexaas_id-client 0.6.0 → 0.7.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
  SHA256:
3
- metadata.gz: c3bd50fd55bf1b80459593dc7cd5b6b95de5126c047e6a13c74019528704f981
4
- data.tar.gz: ff3c81132f73b8ea52d488b55cc9a1a48ecb56d4d9e2a194d743ca402d28f67d
3
+ metadata.gz: f7dba0636a5ef5cd0279be78dbab7ee836e995a50f73be0dbb3c2195742db35c
4
+ data.tar.gz: 7f5a5e5e133db3f5c8702ba4e11a1545d74f37355de0ad91dfd7260c721a212c
5
5
  SHA512:
6
- metadata.gz: dffb7b70907354211a1b6a647203a1b3f649aa0b3455c6f20b90dc590be4eb5b1c8f75ff5ba505cdca7b0218cba15f5c2aaa7e629f0699637b19c8ea585c7b66
7
- data.tar.gz: 55ab1b01de9681e8dbb7df9689b99333cd21746553d7de3de63c8ad01a1387ddc00d47787ef48eeef7a5b6477d3b1432c3202f5d40b3c2401b1294552155a822
6
+ metadata.gz: 46cc9b29c4ffdf03c4cbd931de93a52297714a2e280ddddd1bceaef452a2a0fffd6e0753cd796c2720791f2aa7933f34849f836668f0d24583f9e372c69501c5
7
+ data.tar.gz: 0bd625171195ba87a1b5afcbbfb9a85954f7e73db67250186036e2d254daabac07cfbceebb8f2ad93336565ed6206c384db737b331d6a7b87640d84dc82705b3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nexaas_id-client (0.5.0)
4
+ nexaas_id-client (0.7.0)
5
5
  multi_json (~> 1.11)
6
6
  oauth2 (~> 1.4.0)
7
7
  virtus (~> 1.0)
@@ -46,14 +46,14 @@ GEM
46
46
  domain_name (~> 0.5)
47
47
  ice_nine (0.11.2)
48
48
  json (2.1.0)
49
- jwt (1.5.6)
49
+ jwt (2.1.0)
50
50
  method_source (0.8.2)
51
51
  multi_json (1.13.1)
52
52
  multi_xml (0.6.0)
53
53
  multipart-post (2.0.0)
54
- oauth2 (1.4.0)
55
- faraday (>= 0.8, < 0.13)
56
- jwt (~> 1.0)
54
+ oauth2 (1.4.1)
55
+ faraday (>= 0.8, < 0.16.0)
56
+ jwt (>= 1.0, < 3.0)
57
57
  multi_json (~> 1.3)
58
58
  multi_xml (~> 0.5)
59
59
  rack (>= 1.2, < 3)
data/README.md CHANGED
@@ -53,6 +53,19 @@ NexaasID.configure do |c|
53
53
  end
54
54
  ```
55
55
 
56
+ Or, if you want to instantiate multiple application connections:
57
+
58
+ ```ruby
59
+ require 'nexaas_id'
60
+
61
+ config = NexaasID.Configuration.build do |c|
62
+ c.url = 'https://sandbox.id.nexaas.com'
63
+ c.user_agent = 'My App v1.0'
64
+ c.application_token = 'your-application-token'
65
+ c.application_secret = 'your-application-secret'
66
+ end
67
+ ```
68
+
56
69
  ## Usage
57
70
 
58
71
  The API can be used to access resources owned by an `Identity`, which requires previous authorization from the
@@ -67,6 +80,12 @@ or resources owned by an `Application`, which only requires the application's cr
67
80
  client = NexaasID::Client::Identity.new(user_credentials)
68
81
  ```
69
82
 
83
+ Or passing an explicit configuration:
84
+
85
+ ```ruby
86
+ client = NexaasID::Client::Identity.new(user_credentials, config)
87
+ ```
88
+
70
89
  Here, `user_crendentials` is an object that must have the following attributes available for reading/writing:
71
90
  * access_token
72
91
  * refresh_token
@@ -121,10 +140,17 @@ navbar_url = widget_resource.navbar_url
121
140
 
122
141
  #### Create an instance of NexaasID::Client::Application, as below:
123
142
 
143
+
124
144
  ```ruby
125
145
  client = NexaasID::Client::Application.new
126
146
  ```
127
147
 
148
+ Or passing a explicit configuration:
149
+
150
+ ```ruby
151
+ client = NexaasID::Client::Application.new(config)
152
+ ```
153
+
128
154
  #### Now you have access to the following endpoints:
129
155
 
130
156
  * [SignUp API](https://docs.id.nexaas.com/api/invitation) as `client.signup`
@@ -1,3 +1,5 @@
1
+ require_relative './base'
2
+
1
3
  # Nexaas ID Client for resources not owned by an Identity
2
4
  #
3
5
  # [API]
@@ -7,26 +9,22 @@
7
9
  # client = NexaasID::Client::Application.new
8
10
  # client.sign_up.create(invited: 'john.doe@example.com')
9
11
  #
10
- class NexaasID::Client::Application
11
-
12
- def initialize
12
+ class NexaasID::Client::Application < NexaasID::Client::Base
13
+ def initialize(config = nil)
14
+ super(config)
13
15
  @tokens = {}
14
16
  end
15
17
 
16
- # Provides a SignUp resource.
17
- # @return [NexaasID::Resources::SignUp] the signup resource.
18
- def sign_up
19
- NexaasID::Resources::SignUp.new(token(:invite))
18
+ protected
19
+
20
+ def api_token
21
+ token(:invite)
20
22
  end
21
23
 
22
24
  private
23
25
 
24
26
  attr_reader :tokens
25
27
 
26
- def client
27
- @client ||= NexaasID::Client::OAuth.build
28
- end
29
-
30
28
  def token(scope = nil)
31
29
  token = tokens[scope]
32
30
  return token unless token.nil? || token.expired?
@@ -0,0 +1,23 @@
1
+ class NexaasID::Client::Base
2
+ def initialize(config = nil)
3
+ @config = config || NexaasID.default_configuration
4
+ end
5
+
6
+ # Provides a SignUp resource.
7
+ # @return [NexaasID::Resources::SignUp] the signup resource.
8
+ def sign_up
9
+ NexaasID::Resources::SignUp.new(api_token, config)
10
+ end
11
+
12
+ protected
13
+
14
+ attr_accessor :config
15
+
16
+ def api_token
17
+ raise NotImplementedError
18
+ end
19
+
20
+ def client
21
+ @client ||= NexaasID::Client::OAuth.new(config)
22
+ end
23
+ end
@@ -1,3 +1,5 @@
1
+ require_relative './base'
2
+
1
3
  # Nexaas ID Client for resources owned by an Identity
2
4
  #
3
5
  # [API]
@@ -7,7 +9,7 @@
7
9
  # client = NexaasID::Client::Identity.new(user_credentials)
8
10
  # client.profile.get
9
11
  #
10
- class NexaasID::Client::Identity
12
+ class NexaasID::Client::Identity < NexaasID::Client::Base
11
13
  attr_reader :credentials
12
14
 
13
15
  # Creates an instance of this client.
@@ -17,7 +19,8 @@ class NexaasID::Client::Identity
17
19
  # #refresh_token, #refresh_token=,
18
20
  # #expires_at, #expires_at=
19
21
  # #expires_in, #expires_in=] The user credentials, obtained through the OAuth2 authorization flow.
20
- def initialize(credentials)
22
+ def initialize(credentials, config = nil)
23
+ super(config)
21
24
  @credentials = credentials
22
25
  @token = NexaasID::Client::ExceptionWrapper.new(OAuth2::AccessToken.from_hash(client, hash))
23
26
  end
@@ -25,19 +28,19 @@ class NexaasID::Client::Identity
25
28
  # Provides a Profile resource.
26
29
  # @return [NexaasID::Resources::Profile] the profile resource.
27
30
  def profile
28
- NexaasID::Resources::Profile.new(api)
29
- end
30
-
31
- # Provides a SignUp resource.
32
- # @return [NexaasID::Resources::SignUp] the signup resource.
33
- def sign_up
34
- NexaasID::Resources::SignUp.new(api)
31
+ NexaasID::Resources::Profile.new(api_token, config)
35
32
  end
36
33
 
37
34
  # Provides a Widget resource.
38
35
  # @return [NexaasID::Resources::Widget] the widget resource.
39
36
  def widget
40
- NexaasID::Resources::Widget.new(api)
37
+ NexaasID::Resources::Widget.new(api_token, config)
38
+ end
39
+
40
+ protected
41
+
42
+ def api_token
43
+ token.expired? ? refresh_token : token
41
44
  end
42
45
 
43
46
  private
@@ -46,14 +49,6 @@ class NexaasID::Client::Identity
46
49
 
47
50
  ATTRIBUTES = %i[access_token refresh_token expires_at expires_in].freeze
48
51
 
49
- def api
50
- token.expired? ? refresh_token : token
51
- end
52
-
53
- def client
54
- @client ||= NexaasID::Client::OAuth.build
55
- end
56
-
57
52
  def hash
58
53
  ATTRIBUTES.map { |attr| [attr, credentials.send(attr)] }.to_h
59
54
  end
@@ -2,19 +2,19 @@ require 'oauth2'
2
2
 
3
3
  # OAuth2 client used by NexaasID::Client::Application and NexaasID::Client::Identity.
4
4
  # Provides direct access to the underlying OAuth2 API.
5
- class NexaasID::Client::OAuth
6
-
7
- def self.build
8
- config = NexaasID.configuration
9
- OAuth2::Client.new(config.application_token,
10
- config.application_secret,
11
- site: config.url,
12
- connection_opts: { headers: headers })
5
+ class NexaasID::Client::OAuth < OAuth2::Client
6
+ def initialize(config)
7
+ super(
8
+ config.application_token,
9
+ config.application_secret,
10
+ site: config.url,
11
+ connection_opts: { headers: headers }
12
+ )
13
13
  end
14
14
 
15
15
  private
16
16
 
17
- def self.headers
17
+ def headers
18
18
  { 'Accept': 'application/json', 'Content-type': 'application/json' }
19
19
  end
20
20
  end
@@ -2,6 +2,12 @@ class NexaasID::Configuration
2
2
 
3
3
  attr_accessor :url, :user_agent, :application_token, :application_secret
4
4
 
5
+ def self.build
6
+ config = new
7
+ yield(config) if block_given?
8
+ config
9
+ end
10
+
5
11
  def initialize
6
12
  @url = 'https://id.nexaas.com'
7
13
  @user_agent = "Nexaas ID Ruby Client v#{NexaasID::VERSION}"
@@ -1,10 +1,13 @@
1
1
  # Default root for all resource classes.
2
2
  class NexaasID::Resources::Base
3
+ attr_reader :configuration
4
+
3
5
  # Creates an instance of this class.
4
6
  #
5
7
  # @param [api] api An instance of OAuth2::AccessToken
6
- def initialize(api)
8
+ def initialize(api, config)
7
9
  @api = api
10
+ @configuration = config
8
11
  end
9
12
 
10
13
  protected
@@ -23,6 +23,6 @@ class NexaasID::Resources::Widget < NexaasID::Resources::Base
23
23
  #
24
24
  # @return [String] user's navbar URL
25
25
  def navbar_url
26
- %(#{NexaasID.configuration.url}/api/v1/widgets/navbar?access_token=#{api.token})
26
+ %(#{configuration.url}/api/v1/widgets/navbar?access_token=#{api.token})
27
27
  end
28
28
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module NexaasID
3
- VERSION = "0.6.0".freeze
3
+ VERSION = "0.7.0".freeze
4
4
  end
data/lib/nexaas_id.rb CHANGED
@@ -30,11 +30,11 @@ require "nexaas_id/resources/sign_up"
30
30
  require "nexaas_id/resources/widget"
31
31
 
32
32
  module NexaasID
33
- def self.configuration
34
- @configuration ||= Configuration.new
33
+ def self.default_configuration
34
+ @default_configuration ||= Configuration.new
35
35
  end
36
36
 
37
37
  def self.configure
38
- yield(configuration) if block_given?
38
+ yield(default_configuration) if block_given?
39
39
  end
40
40
  end
@@ -1,12 +1,28 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe NexaasID::Client::Application do
4
- subject { described_class.new }
4
+ describe 'implicit default configuration' do
5
+ subject { described_class.new }
5
6
 
6
- describe '#sign_up' do
7
- it 'provides the signup resource' do
8
- VCR.use_cassette('application/sign_up/client_credentials') do
9
- expect(subject.sign_up).to be_a(NexaasID::Resources::SignUp)
7
+ describe '#sign_up' do
8
+ it 'provides the signup resource' do
9
+ VCR.use_cassette('application/sign_up/client_credentials') do
10
+ expect(subject.sign_up).to be_a(NexaasID::Resources::SignUp)
11
+ end
12
+ end
13
+ end
14
+ end
15
+
16
+ describe 'explicit configuration' do
17
+ subject { described_class.new(configuration) }
18
+
19
+ let(:configuration) { default_configuration }
20
+
21
+ describe '#sign_up' do
22
+ it 'provides the signup resource' do
23
+ VCR.use_cassette('application/sign_up/client_credentials') do
24
+ expect(subject.sign_up).to be_a(NexaasID::Resources::SignUp)
25
+ end
10
26
  end
11
27
  end
12
28
  end
@@ -1,35 +1,55 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe NexaasID::Client::Identity do
4
- subject { described_class.new(user_credentials) }
4
+ describe 'implicit default configuration' do
5
+ subject do
6
+ described_class.new(user_credentials(NexaasID.default_configuration))
7
+ end
5
8
 
6
- describe '#profile' do
7
- it 'provides the profile resource' do
8
- VCR.use_cassette('identity/refresh_token') do
9
- expect(subject.profile).to be_a(NexaasID::Resources::Profile)
9
+ describe '#profile' do
10
+ it 'provides the profile resource' do
11
+ VCR.use_cassette('identity/refresh_token') do
12
+ expect(subject.profile).to be_a(NexaasID::Resources::Profile)
13
+ end
10
14
  end
11
15
  end
12
16
  end
13
17
 
14
- describe '#sign_up' do
15
- it 'provides the signup resource' do
16
- VCR.use_cassette('identity/refresh_token') do
17
- expect(subject.sign_up).to be_a(NexaasID::Resources::SignUp)
18
+ describe 'explicit configuration' do
19
+ subject do
20
+ described_class.new(user_credentials(configuration), configuration)
21
+ end
22
+
23
+ let(:configuration) { default_configuration }
24
+
25
+ describe '#profile' do
26
+ it 'provides the profile resource' do
27
+ VCR.use_cassette('identity/refresh_token') do
28
+ expect(subject.profile).to be_a(NexaasID::Resources::Profile)
29
+ end
18
30
  end
19
31
  end
20
- end
21
32
 
22
- describe '#sign_up' do
23
- it 'provides the widget resource' do
24
- VCR.use_cassette('identity/refresh_token') do
25
- expect(subject.widget).to be_a(NexaasID::Resources::Widget)
33
+ describe '#sign_up' do
34
+ it 'provides the signup resource' do
35
+ VCR.use_cassette('identity/refresh_token') do
36
+ expect(subject.sign_up).to be_a(NexaasID::Resources::SignUp)
37
+ end
26
38
  end
27
39
  end
28
- end
29
40
 
30
- describe '#credentials' do
31
- it 'returns the updated credentials' do
32
- expect(subject.credentials).to eq(user_credentials)
41
+ describe '#sign_up' do
42
+ it 'provides the widget resource' do
43
+ VCR.use_cassette('identity/refresh_token') do
44
+ expect(subject.widget).to be_a(NexaasID::Resources::Widget)
45
+ end
46
+ end
47
+ end
48
+
49
+ describe '#credentials' do
50
+ it 'returns the updated credentials' do
51
+ expect(subject.credentials).to eq(user_credentials(configuration))
52
+ end
33
53
  end
34
54
  end
35
55
  end
@@ -2,37 +2,31 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe NexaasID::Configuration do
5
+ subject do
6
+ described_class.build do |c|
7
+ c.url = 'http://some/where'
8
+ c.user_agent = 'My App v1.0'
9
+ c.application_token = 'some-app-token'
10
+ c.application_secret = 'some-app-secret'
11
+ end
12
+ end
5
13
 
6
14
  it "should use the production Nexaas ID URL by default" do
7
- expect(NexaasID::Configuration.new.url).to eq('https://id.nexaas.com')
15
+ expect(subject.url).to eq('http://some/where')
8
16
  end
9
17
 
10
18
  it "should use a default user agent" do
11
- expect(NexaasID::Configuration.new.user_agent).to eq("Nexaas ID Ruby Client v#{NexaasID::VERSION}")
12
- end
13
-
14
- it 'should allow setting the configuration parameters' do
15
- config = NexaasID::Configuration.new
16
-
17
- config.url = 'https://sandbox.id.nexaas.com'
18
- config.application_token = '58ca7acc-9479-4671-8b7c-745c5a65ce08'
19
- config.application_secret = '8da0d1a5-961d-461f-8ae6-1922db172340'
20
-
21
- expect(config.url).to eq('https://sandbox.id.nexaas.com')
22
- expect(config.application_token).to eq('58ca7acc-9479-4671-8b7c-745c5a65ce08')
23
- expect(config.application_secret).to eq('8da0d1a5-961d-461f-8ae6-1922db172340')
19
+ expect(subject.user_agent).to eq('My App v1.0')
24
20
  end
25
21
 
26
- describe '#url_for' do
27
- let(:configuration) { described_class.new }
22
+ it 'generates an URL to a resource' do
23
+ configuration = subject
28
24
 
29
- it 'generates an URL to a resource' do
30
- expect(configuration.url_for('/api/v1/profile')).to eq('https://id.nexaas.com/api/v1/profile')
25
+ expect(configuration.url_for('/api/v1/profile')).
26
+ to eq('http://some/where/api/v1/profile')
31
27
 
32
- configuration.url = 'https://sandbox.id.nexaas.com/'
33
- expect(configuration.url_for('/api/v1/profile'))
34
- .to eq('https://sandbox.id.nexaas.com/api/v1/profile')
35
- end
28
+ configuration.url = 'https://sandbox.id.nexaas.com/'
29
+ expect(configuration.url_for('/api/v1/profile'))
30
+ .to eq('https://sandbox.id.nexaas.com/api/v1/profile')
36
31
  end
37
-
38
32
  end
@@ -1,7 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe NexaasID::Resources::Profile do
4
- let(:client) { NexaasID::Client::Identity.new(user_credentials) }
4
+ let(:client) do
5
+ configuration = default_configuration
6
+ NexaasID::Client::Identity.new(
7
+ user_credentials(configuration),
8
+ configuration
9
+ )
10
+ end
5
11
  let(:resource) { client.profile }
6
12
 
7
13
  describe "#get" do
@@ -5,7 +5,7 @@ describe NexaasID::Resources::SignUp do
5
5
 
6
6
  describe "#create" do
7
7
  describe 'with application client' do
8
- let(:client) { NexaasID::Client::Application.new }
8
+ let(:client) { NexaasID::Client::Application.new(default_configuration) }
9
9
  subject { resource.create('demurtas@mailinator.com') }
10
10
 
11
11
  it 'invites an user' do
@@ -18,7 +18,10 @@ describe NexaasID::Resources::SignUp do
18
18
  end
19
19
 
20
20
  describe 'with identity client' do
21
- let(:client) { NexaasID::Client::Identity.new(user_credentials) }
21
+ let(:client) do
22
+ configuration = default_configuration
23
+ NexaasID::Client::Identity.new(user_credentials(configuration), configuration)
24
+ end
22
25
  subject { resource.create('demurtas@mailinator.com') }
23
26
 
24
27
  it 'invites an user' do
@@ -1,12 +1,18 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe NexaasID::Resources::Widget do
4
- let(:client) { NexaasID::Client::Identity.new(user_credentials) }
4
+ let(:client) do
5
+ NexaasID::Client::Identity.new(
6
+ user_credentials(configuration),
7
+ configuration
8
+ )
9
+ end
10
+ let(:configuration) { default_configuration }
5
11
  let(:resource) { client.widget }
6
12
 
7
13
  describe "#navbar_url" do
8
14
  subject { resource.navbar_url }
9
- let(:regexp) { %r(#{Regexp.quote(NexaasID.configuration.url)}/api/v1/widgets/navbar\?access_token=(.+?)$) }
15
+ let(:regexp) { %r(#{Regexp.quote(configuration.url)}/api/v1/widgets/navbar\?access_token=(.+?)$) }
10
16
 
11
17
  it 'returns the navbar url for this user' do
12
18
  VCR.use_cassette('identity/widget/navbar_url/success') do
@@ -2,12 +2,11 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe NexaasID do
5
-
6
5
  it 'should have a version number' do
7
6
  expect(NexaasID::VERSION).not_to be_nil
8
7
  end
9
8
 
10
- describe 'configuration' do
9
+ describe 'default configuration' do
11
10
  it 'should be done via block initialization' do
12
11
  NexaasID.configure do |c|
13
12
  c.url = 'http://some/where'
@@ -15,16 +14,18 @@ describe NexaasID do
15
14
  c.application_token = 'some-app-token'
16
15
  c.application_secret = 'some-app-secret'
17
16
  end
18
- expect(NexaasID.configuration.url).to eq('http://some/where')
19
- expect(NexaasID.configuration.user_agent).to eq('My App v1.0')
20
- expect(NexaasID.configuration.application_token).to eq('some-app-token')
21
- expect(NexaasID.configuration.application_secret).to eq('some-app-secret')
17
+
18
+ config = NexaasID.default_configuration
19
+ expect(config.url).to eq('http://some/where')
20
+ expect(config.user_agent).to eq('My App v1.0')
21
+ expect(config.application_token).to eq('some-app-token')
22
+ expect(config.application_secret).to eq('some-app-secret')
22
23
  end
24
+
23
25
  it 'should use a singleton object for the configuration values' do
24
- config1 = NexaasID.configuration
25
- config2 = NexaasID.configuration
26
+ config1 = NexaasID.default_configuration
27
+ config2 = NexaasID.default_configuration
26
28
  expect(config1).to be === config2
27
29
  end
28
30
  end
29
-
30
31
  end
data/spec/spec_helper.rb CHANGED
@@ -17,6 +17,7 @@ require 'vcr'
17
17
  require 'pry'
18
18
  require 'webmock/rspec'
19
19
  require 'support/authorization'
20
+ require 'support/configuration_helper'
20
21
 
21
22
  VCR.configure do |c|
22
23
  c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
@@ -30,13 +31,12 @@ RSpec.configure do |c|
30
31
  c.mock_with :rspec
31
32
  c.example_status_persistence_file_path = '.rspec_persistence'
32
33
  c.include Authorization
34
+ c.include ConfigurationHelper
33
35
 
34
36
  c.before do
35
37
  NexaasID.configure do |config|
36
- # https://sandbox.id.nexaas.com/applications/89e9d504-e2a8-476e-ac94-c33e68399c7e
37
- # Test application - luiz.buiatte+pw.api.test@nexaas.com
38
38
  config.url = ENV['NEXAAS_ID_URL']
39
- config.application_token = ENV['APPLICATION_TOKEN']
39
+ config.application_token = ENV['APPLICATION_TOKEN']
40
40
  config.application_secret = ENV['APPLICATION_SECRET']
41
41
  end
42
42
  end
@@ -2,8 +2,8 @@ require 'faraday-cookie_jar'
2
2
 
3
3
  module Authorization
4
4
 
5
- def authorization_code
6
- connection = Faraday.new(url: NexaasID.configuration.url) do |builder|
5
+ def authorization_code(configuration)
6
+ connection = Faraday.new(url: configuration.url) do |builder|
7
7
  builder.use :cookie_jar
8
8
  builder.adapter Faraday.default_adapter
9
9
  end
@@ -18,14 +18,14 @@ module Authorization
18
18
  connection.post('/sign_in', URI.encode_www_form(data))
19
19
 
20
20
  response = connection.get('oauth/authorize',
21
- client_id: NexaasID.configuration.application_token,
21
+ client_id: configuration.application_token,
22
22
  redirect_uri: 'urn:ietf:wg:oauth:2.0:oob',
23
23
  response_type: 'code',
24
24
  scope: 'profile invite')
25
25
 
26
26
  if(response.headers['location'].nil? || response.headers['location'] == '')
27
27
  data = {
28
- client_id: NexaasID.configuration.application_token,
28
+ client_id: configuration.application_token,
29
29
  commit: 'Authorize',
30
30
  redirect_uri: 'urn:ietf:wg:oauth:2.0:oob',
31
31
  response_type: 'code',
@@ -43,16 +43,19 @@ module Authorization
43
43
  response.body.match(%r{name="authenticity_token" value="(.+?)"}).captures.first
44
44
  end
45
45
 
46
- def access_token
46
+ def access_token(configuration)
47
47
  VCR.use_cassette('access_token') do
48
- client = NexaasID::Client::OAuth.build
49
- client.auth_code.get_token(authorization_code, redirect_uri: 'urn:ietf:wg:oauth:2.0:oob')
48
+ client = NexaasID::Client::OAuth.new(configuration)
49
+ client.auth_code.get_token(
50
+ authorization_code(configuration),
51
+ redirect_uri: 'urn:ietf:wg:oauth:2.0:oob'
52
+ )
50
53
  end
51
54
  end
52
55
 
53
- def user_credentials
56
+ def user_credentials(configuration)
54
57
  OpenStruct.new.tap do |credentials|
55
- token = access_token
58
+ token = access_token(configuration)
56
59
  credentials.access_token = token.token
57
60
  credentials.refresh_token = token.refresh_token
58
61
  credentials.expires_in = token.expires_in
@@ -0,0 +1,11 @@
1
+ module ConfigurationHelper
2
+ def default_configuration
3
+ NexaasID::Configuration.build do |config|
4
+ # https://sandbox.id.nexaas.com/applications/89e9d504-e2a8-476e-ac94-c33e68399c7e
5
+ # Test application - luiz.buiatte+pw.api.test@nexaas.com
6
+ config.url = ENV['NEXAAS_ID_URL']
7
+ config.application_token = ENV['APPLICATION_TOKEN']
8
+ config.application_secret = ENV['APPLICATION_SECRET']
9
+ end
10
+ end
11
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nexaas_id-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rodrigo Tassinari de Oliveira
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2018-10-11 00:00:00.000000000 Z
14
+ date: 2018-10-23 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: multi_json
@@ -262,6 +262,7 @@ files:
262
262
  - lib/nexaas_id.rb
263
263
  - lib/nexaas_id/client.rb
264
264
  - lib/nexaas_id/client/application.rb
265
+ - lib/nexaas_id/client/base.rb
265
266
  - lib/nexaas_id/client/exception.rb
266
267
  - lib/nexaas_id/client/exception_wrapper.rb
267
268
  - lib/nexaas_id/client/identity.rb
@@ -293,6 +294,7 @@ files:
293
294
  - spec/nexaas_id_spec.rb
294
295
  - spec/spec_helper.rb
295
296
  - spec/support/authorization.rb
297
+ - spec/support/configuration_helper.rb
296
298
  homepage: https://github.com/myfreecomm/nexaas-id-client-ruby
297
299
  licenses:
298
300
  - Apache-2.0
@@ -329,3 +331,4 @@ test_files:
329
331
  - spec/nexaas_id_spec.rb
330
332
  - spec/spec_helper.rb
331
333
  - spec/support/authorization.rb
334
+ - spec/support/configuration_helper.rb