roqua-core-api 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/ChangeLog.md +4 -0
- data/core_api.gemspec +5 -6
- data/lib/roqua/core_api/models/active_virtus.rb +1 -1
- data/lib/roqua/core_api/sessions.rb +0 -5
- data/lib/roqua/core_api/version.rb +1 -1
- data/spec/fabricators/auth_session_fabricator.rb +2 -2
- data/spec/fabricators/basic_auth_session_fabricator.rb +1 -1
- data/spec/lib/roqua/core_api/create_dossier_group_spec.rb +1 -1
- data/spec/lib/roqua/core_api/create_dossier_spec.rb +1 -1
- data/spec/lib/roqua/core_api/dossiers_spec.rb +1 -1
- data/spec/lib/roqua/core_api/send_invite_email_spec.rb +1 -1
- data/spec/lib/roqua/core_api/sessions/auth_session_spec.rb +3 -3
- data/spec/lib/roqua/core_api/sessions/token_session_spec.rb +3 -3
- data/spec/lib/roqua/core_api/update_dossier_spec.rb +1 -1
- data/spec/spec_helper.rb +9 -3
- metadata +25 -48
- data/lib/roqua/core_api/sessions/oauth_session.rb +0 -38
- data/lib/roqua/omniauth/rails_initializer.rb +0 -12
- data/lib/roqua/omniauth/strategies/doorkeeper.rb +0 -25
- data/spec/fabricators/oauth_session_fabricator.rb +0 -5
- data/spec/lib/roqua/core_api/sessions/oauth_session_spec.rb +0 -63
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1d24e263c105794df4c647f23f282af5df4cd536397c2219c3a01836032a7206
|
4
|
+
data.tar.gz: d3c11d3f561a874b7a209a4dadb69c34a515148c5db3941478ffa854acdbbd13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e23edc5bcbfe448719868c2a47f92e45de88b14c0e1caa2043aec22cb9191a40c5995e5b80b1b1fc58318eab3d5c97e9b6726d8dd4461e53ee75ade548cb5c7
|
7
|
+
data.tar.gz: d0c3056bf8de5c17febb92df1e8ffc8539dfb57cc4a5ae80bc0c7fdcaf3535fc302420450e1c8af64df42d18eb168df1b4aea27a0a7abc93b77ff04e4dc0ad00
|
data/ChangeLog.md
CHANGED
data/core_api.gemspec
CHANGED
@@ -17,16 +17,15 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
18
|
gem.require_paths = ['lib']
|
19
19
|
|
20
|
-
gem.add_dependency 'httparty', '~> 0.14.0'
|
21
20
|
gem.add_dependency 'active_interaction', '~> 3.2'
|
22
|
-
gem.add_dependency '
|
21
|
+
gem.add_dependency 'httparty', '~> 0.14.0'
|
23
22
|
gem.add_dependency 'virtus', '~> 1.0'
|
24
23
|
|
25
|
-
gem.add_development_dependency 'bundler'
|
24
|
+
gem.add_development_dependency 'bundler'
|
25
|
+
gem.add_development_dependency 'dotenv', '~> 0.10'
|
26
|
+
gem.add_development_dependency 'fabrication', '~> 2.9'
|
26
27
|
gem.add_development_dependency 'rake', '~> 10.0'
|
27
|
-
gem.add_development_dependency 'yard', '~> 0.8'
|
28
28
|
gem.add_development_dependency 'rspec', '~> 3.0'
|
29
|
-
gem.add_development_dependency 'fabrication', '~> 2.9'
|
30
29
|
gem.add_development_dependency 'webmock', '~> 1.17'
|
31
|
-
gem.add_development_dependency '
|
30
|
+
gem.add_development_dependency 'yard', '~> 0.8'
|
32
31
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'httparty'
|
2
2
|
require 'roqua/core_api/sessions/auth_session'
|
3
|
-
require 'roqua/core_api/sessions/oauth_session'
|
4
3
|
require 'roqua/core_api/sessions/token_session'
|
5
4
|
require 'roqua/core_api/sessions/basic_auth_session'
|
6
5
|
require 'roqua/core_api/sessions/hmac_auth_request'
|
@@ -8,10 +7,6 @@ require 'roqua/core_api/sessions/hmac_auth_session'
|
|
8
7
|
|
9
8
|
module Roqua
|
10
9
|
module CoreApi
|
11
|
-
def self.oauth_session(*arguments, &block)
|
12
|
-
Sessions::OAuthSession.new(*arguments, &block)
|
13
|
-
end
|
14
|
-
|
15
10
|
def self.token_session(*arguments, &block)
|
16
11
|
Sessions::TokenSession.new(*arguments, &block)
|
17
12
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
Fabricator(:roqua_core_api_auth_session, from: Roqua::CoreApi::Sessions::AuthSession) do
|
2
|
-
initialize_with { Roqua::CoreApi::Sessions::AuthSession.new core_site: 'http://core.
|
2
|
+
initialize_with { Roqua::CoreApi::Sessions::AuthSession.new core_site: 'http://core.roqua.eu' }
|
3
3
|
end
|
4
4
|
|
5
5
|
Fabricator(:roqua_core_api_token_session, from: Roqua::CoreApi::Sessions::TokenSession) do
|
6
6
|
initialize_with do
|
7
|
-
Roqua::CoreApi::Sessions::TokenSession.new access_token: 'some_access_token', core_site: 'http://core.
|
7
|
+
Roqua::CoreApi::Sessions::TokenSession.new access_token: 'some_access_token', core_site: 'http://core.roqua.eu'
|
8
8
|
end
|
9
9
|
end
|
@@ -2,6 +2,6 @@ Fabricator(:roqua_core_api_basic_auth_session, from: Roqua::CoreApi::Sessions::B
|
|
2
2
|
initialize_with do
|
3
3
|
Roqua::CoreApi::Sessions::BasicAuthSession.new username: 'some_username',
|
4
4
|
password: 'some_password',
|
5
|
-
core_site: 'http://core.
|
5
|
+
core_site: 'http://core.roqua.eu'
|
6
6
|
end
|
7
7
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe CreateDossierGroup do
|
4
|
-
let(:session) { Fabricate :
|
4
|
+
let(:session) { Fabricate :roqua_core_api_token_session }
|
5
5
|
|
6
6
|
it 'performs a post on the /dossier_groups api path' do
|
7
7
|
expect(session).to receive(:post).with('/dossier_groups', dossier_group: {some: 'attributes'},
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe CreateDossier do
|
4
|
-
let(:session) { Fabricate :
|
4
|
+
let(:session) { Fabricate :roqua_core_api_token_session }
|
5
5
|
let(:person) { Fabricate :roqua_core_api_person, id: nil }
|
6
6
|
let(:dossier) { Fabricate :roqua_core_api_dossier, id: nil }
|
7
7
|
let(:response) { httparty_response('id' => 'some_id') }
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Dossiers do
|
4
|
-
let(:session) { Fabricate :
|
4
|
+
let(:session) { Fabricate :roqua_core_api_token_session }
|
5
5
|
let(:dossier_group_id) { 'some_dg_id' }
|
6
6
|
let(:external_identifier) { 'some_eid' }
|
7
7
|
let(:response) { {'headers' => %w(id birth_year gender firstname lastname),
|
@@ -34,7 +34,7 @@ describe AuthSession do
|
|
34
34
|
it 'performs a get request' do
|
35
35
|
allow(session).to receive(:basic_auth).and_return(username: 'some_username', password: 'some_password')
|
36
36
|
allow(session).to receive(:headers).and_return(some: 'header')
|
37
|
-
expect(HTTParty).to receive(:get).with('http://core.
|
37
|
+
expect(HTTParty).to receive(:get).with('http://core.roqua.eu/api/v1/some_path.json',
|
38
38
|
query: {some: 'param'},
|
39
39
|
headers: {some: 'header'},
|
40
40
|
basic_auth: {username: 'some_username', password: 'some_password'},
|
@@ -44,7 +44,7 @@ describe AuthSession do
|
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'returns the response on sucess status' do
|
47
|
-
stub_request(:get, 'http://core.
|
47
|
+
stub_request(:get, 'http://core.roqua.eu/api/v1/some_path.json?').to_return(
|
48
48
|
status: 201,
|
49
49
|
body: '{ "success": true }',
|
50
50
|
headers: { 'Content-Type' => 'application/json' })
|
@@ -52,7 +52,7 @@ describe AuthSession do
|
|
52
52
|
end
|
53
53
|
|
54
54
|
it 'returns the response on a 422 status' do
|
55
|
-
stub_request(:get, 'http://core.
|
55
|
+
stub_request(:get, 'http://core.roqua.eu/api/v1/some_path.json?').to_return(
|
56
56
|
status: 422,
|
57
57
|
body: '{ "errors": { "column": ["wrong"] } }',
|
58
58
|
headers: { 'Content-Type' => 'application/json' })
|
@@ -27,7 +27,7 @@ describe TokenSession do
|
|
27
27
|
|
28
28
|
describe '#logout' do
|
29
29
|
it 'sends a put request to the session#destroy' do
|
30
|
-
expect(HTTParty).to receive(:delete).with("http://core.
|
30
|
+
expect(HTTParty).to receive(:delete).with("http://core.roqua.eu/api/v1sessions/destroy.json",
|
31
31
|
headers: {"Authorization" => "Session some_access_token"},
|
32
32
|
query: {},
|
33
33
|
basic_auth: nil,
|
@@ -49,7 +49,7 @@ describe TokenSession do
|
|
49
49
|
|
50
50
|
describe '#access_denied' do
|
51
51
|
it 'raises a no_session error when response is 401 with a no_session response' do
|
52
|
-
stub_request(:get, 'http://core.
|
52
|
+
stub_request(:get, 'http://core.roqua.eu/api/v1/some_path.json?').to_return(
|
53
53
|
status: 401,
|
54
54
|
body: '{ "no_session": true }',
|
55
55
|
headers: { 'Content-Type' => 'application/json' })
|
@@ -57,7 +57,7 @@ describe TokenSession do
|
|
57
57
|
end
|
58
58
|
|
59
59
|
it 'raises a unauthorized error when response is 401 without a no_session response' do
|
60
|
-
stub_request(:get, 'http://core.
|
60
|
+
stub_request(:get, 'http://core.roqua.eu/api/v1/some_path.json?').to_return(
|
61
61
|
status: 401,
|
62
62
|
body: '',
|
63
63
|
headers: { 'Content-Type' => 'application/json' })
|
data/spec/spec_helper.rb
CHANGED
@@ -2,15 +2,21 @@ require 'rspec'
|
|
2
2
|
require 'fabrication'
|
3
3
|
|
4
4
|
require 'dotenv'
|
5
|
-
Dotenv.load(File.expand_path("
|
5
|
+
Dotenv.load(File.expand_path("../.env", File.dirname(__dir__)))
|
6
6
|
|
7
7
|
require 'roqua-core-api'
|
8
8
|
include Roqua::CoreApi
|
9
9
|
include Roqua::CoreApi::Sessions
|
10
10
|
include Roqua::CoreApi::Models
|
11
11
|
|
12
|
-
|
12
|
+
# It seems sometimes the Rails constant is defined and Rails.root is injected (which is nil at that moment) resulting
|
13
|
+
# in missing fabricators. Let's just set the path to the current directory to fix this. See:
|
14
|
+
# https://github.com/paulelliott/fabrication/blob/42db96f11cbf80d22bd9c87dbf6740894c2b2bdc/lib/fabrication/config.rb#L42
|
15
|
+
Fabrication::Config.path_prefix = ['.']
|
16
|
+
Fabrication.manager.load_definitions
|
13
17
|
|
14
|
-
|
18
|
+
Dir[File.join(File.expand_path(__dir__), 'support', '*.rb')].each { |f| require f }
|
19
|
+
|
20
|
+
I18n.load_path << Dir[File.join(File.expand_path(__dir__), '..', 'config', 'locales', '*.yml')]
|
15
21
|
I18n.enforce_available_locales = false
|
16
22
|
I18n.default_locale = :nl
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: roqua-core-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marten Veldthuis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: httparty
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 0.14.0
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 0.14.0
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: active_interaction
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,19 +25,19 @@ dependencies:
|
|
39
25
|
- !ruby/object:Gem::Version
|
40
26
|
version: '3.2'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
28
|
+
name: httparty
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
44
30
|
requirements:
|
45
31
|
- - "~>"
|
46
32
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
33
|
+
version: 0.14.0
|
48
34
|
type: :runtime
|
49
35
|
prerelease: false
|
50
36
|
version_requirements: !ruby/object:Gem::Requirement
|
51
37
|
requirements:
|
52
38
|
- - "~>"
|
53
39
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
40
|
+
version: 0.14.0
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: virtus
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -70,72 +56,72 @@ dependencies:
|
|
70
56
|
name: bundler
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
72
58
|
requirements:
|
73
|
-
- - "
|
59
|
+
- - ">="
|
74
60
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
61
|
+
version: '0'
|
76
62
|
type: :development
|
77
63
|
prerelease: false
|
78
64
|
version_requirements: !ruby/object:Gem::Requirement
|
79
65
|
requirements:
|
80
|
-
- - "
|
66
|
+
- - ">="
|
81
67
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
68
|
+
version: '0'
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
70
|
+
name: dotenv
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
86
72
|
requirements:
|
87
73
|
- - "~>"
|
88
74
|
- !ruby/object:Gem::Version
|
89
|
-
version: '10
|
75
|
+
version: '0.10'
|
90
76
|
type: :development
|
91
77
|
prerelease: false
|
92
78
|
version_requirements: !ruby/object:Gem::Requirement
|
93
79
|
requirements:
|
94
80
|
- - "~>"
|
95
81
|
- !ruby/object:Gem::Version
|
96
|
-
version: '10
|
82
|
+
version: '0.10'
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
84
|
+
name: fabrication
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
100
86
|
requirements:
|
101
87
|
- - "~>"
|
102
88
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
89
|
+
version: '2.9'
|
104
90
|
type: :development
|
105
91
|
prerelease: false
|
106
92
|
version_requirements: !ruby/object:Gem::Requirement
|
107
93
|
requirements:
|
108
94
|
- - "~>"
|
109
95
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
96
|
+
version: '2.9'
|
111
97
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
98
|
+
name: rake
|
113
99
|
requirement: !ruby/object:Gem::Requirement
|
114
100
|
requirements:
|
115
101
|
- - "~>"
|
116
102
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
103
|
+
version: '10.0'
|
118
104
|
type: :development
|
119
105
|
prerelease: false
|
120
106
|
version_requirements: !ruby/object:Gem::Requirement
|
121
107
|
requirements:
|
122
108
|
- - "~>"
|
123
109
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
110
|
+
version: '10.0'
|
125
111
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
112
|
+
name: rspec
|
127
113
|
requirement: !ruby/object:Gem::Requirement
|
128
114
|
requirements:
|
129
115
|
- - "~>"
|
130
116
|
- !ruby/object:Gem::Version
|
131
|
-
version: '
|
117
|
+
version: '3.0'
|
132
118
|
type: :development
|
133
119
|
prerelease: false
|
134
120
|
version_requirements: !ruby/object:Gem::Requirement
|
135
121
|
requirements:
|
136
122
|
- - "~>"
|
137
123
|
- !ruby/object:Gem::Version
|
138
|
-
version: '
|
124
|
+
version: '3.0'
|
139
125
|
- !ruby/object:Gem::Dependency
|
140
126
|
name: webmock
|
141
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -151,19 +137,19 @@ dependencies:
|
|
151
137
|
- !ruby/object:Gem::Version
|
152
138
|
version: '1.17'
|
153
139
|
- !ruby/object:Gem::Dependency
|
154
|
-
name:
|
140
|
+
name: yard
|
155
141
|
requirement: !ruby/object:Gem::Requirement
|
156
142
|
requirements:
|
157
143
|
- - "~>"
|
158
144
|
- !ruby/object:Gem::Version
|
159
|
-
version: '0.
|
145
|
+
version: '0.8'
|
160
146
|
type: :development
|
161
147
|
prerelease: false
|
162
148
|
version_requirements: !ruby/object:Gem::Requirement
|
163
149
|
requirements:
|
164
150
|
- - "~>"
|
165
151
|
- !ruby/object:Gem::Version
|
166
|
-
version: '0.
|
152
|
+
version: '0.8'
|
167
153
|
description: Provides authenticated access to Core
|
168
154
|
email: marten@veldthuis.com
|
169
155
|
executables: []
|
@@ -214,19 +200,15 @@ files:
|
|
214
200
|
- lib/roqua/core_api/sessions/basic_auth_session.rb
|
215
201
|
- lib/roqua/core_api/sessions/hmac_auth_request.rb
|
216
202
|
- lib/roqua/core_api/sessions/hmac_auth_session.rb
|
217
|
-
- lib/roqua/core_api/sessions/oauth_session.rb
|
218
203
|
- lib/roqua/core_api/sessions/token_session.rb
|
219
204
|
- lib/roqua/core_api/sso_login.rb
|
220
205
|
- lib/roqua/core_api/update_dossier.rb
|
221
206
|
- lib/roqua/core_api/update_person.rb
|
222
207
|
- lib/roqua/core_api/version.rb
|
223
|
-
- lib/roqua/omniauth/rails_initializer.rb
|
224
|
-
- lib/roqua/omniauth/strategies/doorkeeper.rb
|
225
208
|
- spec/core_api_spec.rb
|
226
209
|
- spec/fabricators/auth_session_fabricator.rb
|
227
210
|
- spec/fabricators/basic_auth_session_fabricator.rb
|
228
211
|
- spec/fabricators/dossier_fabricator.rb
|
229
|
-
- spec/fabricators/oauth_session_fabricator.rb
|
230
212
|
- spec/fabricators/person_fabricator.rb
|
231
213
|
- spec/lib/roqua/core_api/create_dossier_group_spec.rb
|
232
214
|
- spec/lib/roqua/core_api/create_dossier_spec.rb
|
@@ -239,7 +221,6 @@ files:
|
|
239
221
|
- spec/lib/roqua/core_api/send_text_message_to_spec.rb
|
240
222
|
- spec/lib/roqua/core_api/sessions/auth_session_spec.rb
|
241
223
|
- spec/lib/roqua/core_api/sessions/basic_auth_session_spec.rb
|
242
|
-
- spec/lib/roqua/core_api/sessions/oauth_session_spec.rb
|
243
224
|
- spec/lib/roqua/core_api/sessions/token_session_spec.rb
|
244
225
|
- spec/lib/roqua/core_api/update_dossier_spec.rb
|
245
226
|
- spec/spec_helper.rb
|
@@ -263,8 +244,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
263
244
|
- !ruby/object:Gem::Version
|
264
245
|
version: '0'
|
265
246
|
requirements: []
|
266
|
-
|
267
|
-
rubygems_version: 2.6.8
|
247
|
+
rubygems_version: 3.0.3
|
268
248
|
signing_key:
|
269
249
|
specification_version: 4
|
270
250
|
summary: API wrapper gem around Core's API
|
@@ -273,7 +253,6 @@ test_files:
|
|
273
253
|
- spec/fabricators/auth_session_fabricator.rb
|
274
254
|
- spec/fabricators/basic_auth_session_fabricator.rb
|
275
255
|
- spec/fabricators/dossier_fabricator.rb
|
276
|
-
- spec/fabricators/oauth_session_fabricator.rb
|
277
256
|
- spec/fabricators/person_fabricator.rb
|
278
257
|
- spec/lib/roqua/core_api/create_dossier_group_spec.rb
|
279
258
|
- spec/lib/roqua/core_api/create_dossier_spec.rb
|
@@ -286,9 +265,7 @@ test_files:
|
|
286
265
|
- spec/lib/roqua/core_api/send_text_message_to_spec.rb
|
287
266
|
- spec/lib/roqua/core_api/sessions/auth_session_spec.rb
|
288
267
|
- spec/lib/roqua/core_api/sessions/basic_auth_session_spec.rb
|
289
|
-
- spec/lib/roqua/core_api/sessions/oauth_session_spec.rb
|
290
268
|
- spec/lib/roqua/core_api/sessions/token_session_spec.rb
|
291
269
|
- spec/lib/roqua/core_api/update_dossier_spec.rb
|
292
270
|
- spec/spec_helper.rb
|
293
271
|
- spec/support/httpparty_helpers.rb
|
294
|
-
has_rdoc:
|
@@ -1,38 +0,0 @@
|
|
1
|
-
module Roqua
|
2
|
-
module CoreApi
|
3
|
-
module Sessions
|
4
|
-
class OAuthSession < AuthSession
|
5
|
-
attr_reader :access_token
|
6
|
-
|
7
|
-
def initialize(access_token:, **additional_arguments)
|
8
|
-
@access_token = access_token
|
9
|
-
super additional_arguments
|
10
|
-
end
|
11
|
-
|
12
|
-
def logout_url(return_to:)
|
13
|
-
"#{core_site}/session/destroy?token=#{access_token}&return_to=#{CGI.escape return_to}"
|
14
|
-
end
|
15
|
-
|
16
|
-
# ping the server to check if session is still valid.
|
17
|
-
# Will throw NoSession as usual if not.
|
18
|
-
def ping
|
19
|
-
get "/ping"
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
def access_denied(response)
|
25
|
-
if response['no_session']
|
26
|
-
fail NoSession
|
27
|
-
else
|
28
|
-
fail Unauthorized
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def headers(_request_method, _path, _params)
|
33
|
-
{"Authorization" => "Bearer #{access_token}"}
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
require 'omniauth-oauth2'
|
2
|
-
require 'roqua/omniauth/strategies/doorkeeper'
|
3
|
-
|
4
|
-
OmniAuth.config.logger = Rails.logger
|
5
|
-
|
6
|
-
Rails.application.config.middleware.use OmniAuth::Builder do
|
7
|
-
provider :doorkeeper,
|
8
|
-
ENV.fetch('CORE_OAUTH_CLIENT_ID'),
|
9
|
-
ENV.fetch('CORE_OAUTH_CLIENT_SECRET'),
|
10
|
-
client_options: {site: ENV.fetch('CORE_SITE')},
|
11
|
-
authorize_params: {organization_id: ENV['CORE_ORGANIZATION']}
|
12
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
module OmniAuth
|
2
|
-
module Strategies
|
3
|
-
class Doorkeeper < OmniAuth::Strategies::OAuth2
|
4
|
-
option :name, :doorkeeper
|
5
|
-
option :client_options, site: 'http://core.dev',
|
6
|
-
authorize_path: '/oauth/authorize'
|
7
|
-
|
8
|
-
uid do
|
9
|
-
raw_info["id"]
|
10
|
-
end
|
11
|
-
|
12
|
-
info do
|
13
|
-
{dossier_id: raw_info['dossier_id'],
|
14
|
-
username: raw_info['username'],
|
15
|
-
role: raw_info['role'],
|
16
|
-
person_id: raw_info['person_id'],
|
17
|
-
dossier_groups: raw_info['dossier_groups']}
|
18
|
-
end
|
19
|
-
|
20
|
-
def raw_info
|
21
|
-
@raw_info ||= access_token.get('/api/v1/me.json').parsed['me']
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,63 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'webmock/rspec'
|
3
|
-
|
4
|
-
describe OAuthSession do
|
5
|
-
let(:session) { Fabricate :roqua_core_api_oauth_session }
|
6
|
-
let(:response) { double('response', code: 201, parsed_response: 'some_response') }
|
7
|
-
|
8
|
-
describe '#initialize' do
|
9
|
-
it 'sets the access_token instance variable' do
|
10
|
-
session = Roqua::CoreApi.oauth_session access_token: 'some_access_token'
|
11
|
-
expect(session.access_token).to eq('some_access_token')
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'allows to override the core_site variable' do
|
15
|
-
session = Roqua::CoreApi.oauth_session access_token: 'some_access_token', core_site: 'some_core_site'
|
16
|
-
expect(session.core_site).to eq('some_core_site')
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'defaults the AuthSession core_site CORE_SITE env variable default value' do
|
20
|
-
original_env_core_site = ENV['CORE_SITE']
|
21
|
-
ENV['CORE_SITE'] = 'some_env_core_site'
|
22
|
-
session = Roqua::CoreApi.oauth_session access_token: 'some_access_token'
|
23
|
-
ENV['CORE_SITE'] = original_env_core_site
|
24
|
-
expect(session.core_site).to eq('some_env_core_site')
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe '#logout_url' do
|
29
|
-
it 'returns the oauth session destroy url with an escaped redirect_to parameter' do
|
30
|
-
expect(session.logout_url return_to: 'some redirect to')
|
31
|
-
.to eq('http://core.dev/session/destroy?token=some_access_token&return_to=some+redirect+to')
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe 'headers' do
|
36
|
-
it 'sets the Authorization header' do
|
37
|
-
expect(HTTParty).to receive(:get).with(an_instance_of(String),
|
38
|
-
headers: {"Authorization" => "Bearer some_access_token"},
|
39
|
-
query: {},
|
40
|
-
basic_auth: nil,
|
41
|
-
timeout: nil).and_return(response)
|
42
|
-
session.get 'some_path'
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe '#access_denied' do
|
47
|
-
it 'raises a no_session error when response is 401 with a no_session response' do
|
48
|
-
stub_request(:get, 'http://core.dev/api/v1/some_path.json?').to_return(
|
49
|
-
status: 401,
|
50
|
-
body: '{ "no_session": true }',
|
51
|
-
headers: { 'Content-Type' => 'application/json' })
|
52
|
-
expect { session.get '/some_path' }.to raise_error(NoSession)
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'raises a unauthorized error when response is 401 without a no_session response' do
|
56
|
-
stub_request(:get, 'http://core.dev/api/v1/some_path.json?').to_return(
|
57
|
-
status: 401,
|
58
|
-
body: '',
|
59
|
-
headers: { 'Content-Type' => 'application/json' })
|
60
|
-
expect { session.get '/some_path' }.to raise_error(Unauthorized)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|