roqua-core-api 0.2.1 → 0.2.2

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: afcb8f55c765892ee686c50b9b069af7a42242cc
4
- data.tar.gz: 231798c7c1c9f410237f4d9f4d683be12d3c8188
3
+ metadata.gz: a72749c7f2600d3b71d258d719abc54d8e81f6ca
4
+ data.tar.gz: cd987f3e2b2784a18f901c09bcbe624c69f97943
5
5
  SHA512:
6
- metadata.gz: 053913480e04a70b7e0521b65ebc4bfac5fcb1901efcd7864a34e98642f1570e8c186bf54fd65271b88ead86d982c6e9575dd677d340efc4cfe43102770d7764
7
- data.tar.gz: 9eb9cd12a83f09c7a8e956098b42d305ea639020a085eb3240403b90599b743951f5b442d140199eca9f743224f0f2f27a63c036707d75bd0ae7f22708311a91
6
+ metadata.gz: 6ecc43438656a7fd8336060b40f27ce0a3325a6382edc494ad465aa90f82a126077d1c3c838b32baebbafa7feab364beee5e063320fbbbad122937b46d16087f
7
+ data.tar.gz: d23c4e9df670e6e818e492f97ef7e412f1814fe1c7e5f6d49fa414e716f87db6b5bb878c86098558c1bf146ab3a7bf9e75e30d35428ba101c36115c7fc571c5c
data/ChangeLog.md CHANGED
@@ -1,3 +1,9 @@
1
+ ### 0.2.2
2
+
3
+ * Added Sessions::HmacAuthSession
4
+ * Added Sessions::HmacAuthRequest
5
+ * Added SsoLogin
6
+
1
7
  ### 0.2.1
2
8
 
3
9
  * Allow SendInviteEmail to receive a person_id instead of a dossier_id
@@ -13,40 +13,28 @@ module Roqua
13
13
 
14
14
  def get(path, timeout: default_timeout, **params)
15
15
  perform_request_or_fail do
16
- HTTParty.get(full_url_for(path),
17
- headers: headers,
18
- query: params,
19
- basic_auth: basic_auth,
20
- timeout: timeout)
16
+ HTTParty.get full_url_for(path),
17
+ query_string_options('GET', path, params, timeout: timeout)
21
18
  end
22
19
  end
23
20
 
24
21
  def post(path, timeout: default_timeout, **params)
25
22
  perform_request_or_fail do
26
- HTTParty.post(full_url_for(path),
27
- headers: headers.merge('Content-Type' => 'application/json'),
28
- body: params.to_json,
29
- basic_auth: basic_auth,
30
- timeout: timeout)
23
+ HTTParty.post full_url_for(path),
24
+ json_body_options('POST', path, params, timeout: timeout)
31
25
  end
32
26
  end
33
27
 
34
28
  def patch(path, timeout: default_timeout, **params)
35
29
  perform_request_or_fail do
36
- HTTParty.patch(full_url_for(path),
37
- headers: headers.merge('Content-Type' => 'application/json'),
38
- body: params.to_json,
39
- basic_auth: basic_auth,
40
- timeout: timeout)
30
+ HTTParty.patch full_url_for(path),
31
+ json_body_options('PATCH', path, params, timeout: timeout)
41
32
  end
42
33
  end
43
34
 
44
35
  def delete(path, timeout: default_timeout, **params)
45
- HTTParty.delete(full_url_for(path),
46
- headers: headers,
47
- query: params,
48
- basic_auth: basic_auth,
49
- timeout: timeout)
36
+ HTTParty.delete full_url_for(path),
37
+ query_string_options('DELETE', path, params, timeout: timeout)
50
38
  end
51
39
 
52
40
  private
@@ -63,6 +51,20 @@ module Roqua
63
51
  end
64
52
  end
65
53
 
54
+ def json_body_options(request_method, path, params, timeout:)
55
+ {headers: headers(request_method, path, params).merge('Content-Type' => 'application/json'),
56
+ body: params.to_json,
57
+ basic_auth: basic_auth,
58
+ timeout: timeout}
59
+ end
60
+
61
+ def query_string_options(request_method, path, params, timeout:)
62
+ {headers: headers(request_method, path, params),
63
+ query: params,
64
+ basic_auth: basic_auth,
65
+ timeout: timeout}
66
+ end
67
+
66
68
  def full_url_for(path)
67
69
  core_site + api_base + path + '.json'
68
70
  end
@@ -71,7 +73,7 @@ module Roqua
71
73
  '/api/v1'
72
74
  end
73
75
 
74
- def headers
76
+ def headers(_request_method, _path, _params)
75
77
  {}
76
78
  end
77
79
 
@@ -0,0 +1,52 @@
1
+ module Roqua
2
+ module CoreApi
3
+ module Sessions
4
+ # Make a single hmac signed request.
5
+ # HmacAuthRequest.new(consumer_key: 'mykey', consumer_secret: '...')
6
+ # HmacAuthRequest.new(consumer_key: 'mykey', hmac: '...', nonce: '...', timestamp: 1467704698)
7
+ class HmacAuthRequest < AuthSession
8
+ attr_reader :consumer_key, :consumer_secret, :timestamp, :nonce
9
+
10
+ def initialize(consumer_key: ENV.fetch('CORE_CONSUMER_KEY'),
11
+ consumer_secret: ENV.fetch('CORE_CONSUMER_SECRET'),
12
+ timestamp: Time.now.to_i,
13
+ nonce: SecureRandom.urlsafe_base64(32),
14
+ hmac: nil,
15
+ **additional_arguments)
16
+ @consumer_key = consumer_key
17
+ @consumer_secret = consumer_secret
18
+ @timestamp = timestamp
19
+ @nonce = nonce
20
+ @hmac = hmac
21
+ super additional_arguments
22
+ end
23
+
24
+ def headers(request_method, path, params)
25
+ {'Authorization' => "HMAC #{consumer_key}:#{hmac(request_method, path, params)}:#{nonce}:#{timestamp}"}
26
+ end
27
+
28
+ # handle 401 response.
29
+ def access_denied(response)
30
+ fail Unauthorized, response
31
+ end
32
+
33
+ private
34
+
35
+ def hmac(request_method, path, params)
36
+ @hmac || calculate_hmac(request_method, path, params)
37
+ end
38
+
39
+ def calculate_hmac(request_method, path, params)
40
+ checker = Authmac::HmacChecker.new(consumer_secret, '|', 'sha256')
41
+ params_to_sign = params.merge \
42
+ 'request_method' => request_method,
43
+ 'request_path' => "/api/v1#{path}",
44
+ 'timestamp' => timestamp.to_s,
45
+ 'nonce' => nonce,
46
+ 'consumer_key' => consumer_key
47
+ checker.sign(params_to_sign.with_indifferent_access)
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,25 @@
1
+ module Roqua
2
+ module CoreApi
3
+ module Sessions
4
+ class HmacAuthSession < AuthSession
5
+ attr_reader :consumer_key, :consumer_secret
6
+
7
+ delegate :headers, :access_denied, to: :hmac_auth_request
8
+
9
+ def initialize(consumer_key: ENV.fetch('CORE_CONSUMER_KEY'),
10
+ consumer_secret: ENV.fetch('CORE_CONSUMER_SECRET'),
11
+ **additional_arguments)
12
+ @consumer_key = consumer_key
13
+ @consumer_secret = consumer_secret
14
+ super additional_arguments
15
+ end
16
+
17
+ private
18
+
19
+ def hmac_auth_request
20
+ HmacAuthRequest.new(consumer_key: consumer_key, consumer_secret: consumer_secret)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -29,7 +29,7 @@ module Roqua
29
29
  end
30
30
  end
31
31
 
32
- def headers
32
+ def headers(_request_method, _path, _params)
33
33
  {"Authorization" => "Bearer #{access_token}"}
34
34
  end
35
35
  end
@@ -29,7 +29,7 @@ module Roqua
29
29
  end
30
30
  end
31
31
 
32
- def headers
32
+ def headers(_request_method, _path, _params)
33
33
  {"Authorization" => "Session #{access_token}"}
34
34
  end
35
35
  end
@@ -3,6 +3,8 @@ require 'roqua/core_api/sessions/auth_session'
3
3
  require 'roqua/core_api/sessions/oauth_session'
4
4
  require 'roqua/core_api/sessions/token_session'
5
5
  require 'roqua/core_api/sessions/basic_auth_session'
6
+ require 'roqua/core_api/sessions/hmac_auth_request'
7
+ require 'roqua/core_api/sessions/hmac_auth_session'
6
8
 
7
9
  module Roqua
8
10
  module CoreApi
@@ -17,5 +19,9 @@ module Roqua
17
19
  def self.basic_auth_session(*arguments, &block)
18
20
  Sessions::BasicAuthSession.new(*arguments, &block)
19
21
  end
22
+
23
+ def self.hmac_auth_request(*arguments)
24
+ Sessions::HmacAuthRequest(*arguments)
25
+ end
20
26
  end
21
27
  end
@@ -0,0 +1,28 @@
1
+ module Roqua
2
+ module CoreApi
3
+ # @api private
4
+ class SsoLogin < Base
5
+ object :session, class: Sessions::AuthSession
6
+ string :organization_id
7
+ string :dossier_group_id
8
+ string :external_identifier
9
+ hash :extra_params, strip: false, default: {}
10
+
11
+ def execute
12
+ response = session.get "/sso/login", **sso_params
13
+ if response.code == 422
14
+ errors_to_usecase response
15
+ end
16
+ response['token_session']
17
+ end
18
+
19
+ def sso_params
20
+ extra_params.merge(
21
+ organization_id: organization_id,
22
+ dossier_group_id: dossier_group_id,
23
+ external_identifier: external_identifier
24
+ ).symbolize_keys
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,5 +1,5 @@
1
1
  module Roqua
2
2
  module CoreApi
3
- VERSION = '0.2.1'
3
+ VERSION = '0.2.2'
4
4
  end
5
5
  end
@@ -25,6 +25,7 @@ module Roqua
25
25
  autoload :Person
26
26
  autoload :SendEmailTo
27
27
  autoload :SendInviteEmail
28
+ autoload :SsoLogin
28
29
  autoload :UpdatePerson
29
30
  autoload :UpdateDossier
30
31
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roqua-core-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marten Veldthuis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-05 00:00:00.000000000 Z
11
+ date: 2016-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -210,8 +210,11 @@ files:
210
210
  - lib/roqua/core_api/sessions.rb
211
211
  - lib/roqua/core_api/sessions/auth_session.rb
212
212
  - lib/roqua/core_api/sessions/basic_auth_session.rb
213
+ - lib/roqua/core_api/sessions/hmac_auth_request.rb
214
+ - lib/roqua/core_api/sessions/hmac_auth_session.rb
213
215
  - lib/roqua/core_api/sessions/oauth_session.rb
214
216
  - lib/roqua/core_api/sessions/token_session.rb
217
+ - lib/roqua/core_api/sso_login.rb
215
218
  - lib/roqua/core_api/update_dossier.rb
216
219
  - lib/roqua/core_api/update_person.rb
217
220
  - lib/roqua/core_api/version.rb
@@ -258,7 +261,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
258
261
  version: '0'
259
262
  requirements: []
260
263
  rubyforge_project:
261
- rubygems_version: 2.4.8
264
+ rubygems_version: 2.5.1
262
265
  signing_key:
263
266
  specification_version: 4
264
267
  summary: API wrapper gem around Core's API