authkeeper 0.1.12 → 0.1.13

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 35fee3ca91b02463c3ae188eaac29ec61a1648037e9d9fe4afc22c7111cd14f9
4
- data.tar.gz: a5dfcc76f5178fcd781dc11953caf07c0b2642ce67df97cd9ab2321bd84bda33
3
+ metadata.gz: c436194b9b10209087de9a23e793a03cb9dc222748fe9b2d040d17e84b1f0b3b
4
+ data.tar.gz: 73af525eb9235b3d3e0cc8c31159d5665c42a829b3548ba0ce2e9dfd676791bb
5
5
  SHA512:
6
- metadata.gz: 87bbb1e064c3895257a4e52f7562fd01c4bea1fec9bc42a9d09672990af592105a598b26e89a9edfba421704f06443e33f3a653f61690b419744198cd780c8b1
7
- data.tar.gz: 5e4390d669b30a5bab62ead49016f407b201b7c2c5c97240ddfe6b2c266ee110bbd203e93d903dc53904616ce973ae6f4b40768e7a53bd16084a2a882622042b
6
+ metadata.gz: 4ad5ea1075dfac7c1b18f12b00eb4ce3a3ff17c8aace3a603dd6660fc0210630d672d4496ede00305f8b84b115833c97bb001dd6d5c187ee88367b877053ee7b
7
+ data.tar.gz: c98938d5da6d1fb5f5c333143384806fcfd0bffed5a2c45fdef6cbdd0e1b338fe20bc1bd285952bee8aec112d72e4bab3b8b7a7add03acc6951ef1c2dd2e0596
@@ -5,7 +5,7 @@ module Authkeeper
5
5
  module Requests
6
6
  module FetchAccessToken
7
7
  def fetch_access_token(client_id:, client_secret:, code:, redirect_uri:)
8
- post(
8
+ form_post(
9
9
  path: 'oauth2/v4/token',
10
10
  params: {
11
11
  grant_type: 'authorization_code',
@@ -22,8 +22,7 @@ module Authkeeper
22
22
  }
23
23
  end
24
24
 
25
- # rubocop: disable Metrics/AbcSize
26
- def post(path:, body: nil, headers: nil)
25
+ def no_params_post(path:, body: nil, headers: nil)
27
26
  if Rails.env.test? && connection.adapter != 'Faraday::Adapter::Test'
28
27
  raise StandardError, 'please stub request in test env'
29
28
  end
@@ -32,6 +31,23 @@ module Authkeeper
32
31
  response.body if response.success?
33
32
  end
34
33
 
34
+ def post(path:, body: {}, params: {}, headers: {}) # rubocop: disable Metrics/AbcSize
35
+ if Rails.env.test? && connection.adapter != 'Faraday::Adapter::Test'
36
+ raise StandardError, 'please stub request in test env'
37
+ end
38
+
39
+ response = connection.post(path) do |request|
40
+ params.each do |param, value|
41
+ request.params[param] = value
42
+ end
43
+ headers.each do |header, value|
44
+ request.headers[header] = value
45
+ end
46
+ request.body = body.to_json
47
+ end
48
+ response.body if response.success?
49
+ end
50
+
35
51
  def form_post(path:, body: {}, params: {}, headers: {})
36
52
  if Rails.env.test? && connection.adapter != 'Faraday::Adapter::Test'
37
53
  raise StandardError, 'please stub request in test env'
@@ -7,9 +7,9 @@ module Authkeeper
7
7
  module Requests
8
8
  module AccessToken
9
9
  def fetch_access_token(client_id:, redirect_url:, device_id:, code:, state:, code_verifier:)
10
- post(
10
+ form_post(
11
11
  path: 'oauth2/auth',
12
- body: URI.encode_www_form({
12
+ body: {
13
13
  grant_type: 'authorization_code',
14
14
  client_id: client_id,
15
15
  device_id: device_id,
@@ -17,7 +17,7 @@ module Authkeeper
17
17
  state: state,
18
18
  redirect_uri: redirect_url,
19
19
  code_verifier: code_verifier
20
- }),
20
+ },
21
21
  headers: {
22
22
  'Content-Type' => 'application/x-www-form-urlencoded'
23
23
  }
@@ -25,15 +25,15 @@ module Authkeeper
25
25
  end
26
26
 
27
27
  def refresh_access_token(client_id:, refresh_token:, device_id:, state:)
28
- post(
28
+ form_post(
29
29
  path: 'oauth2/auth',
30
- body: URI.encode_www_form({
30
+ body: {
31
31
  grant_type: 'refresh_token',
32
32
  client_id: client_id,
33
33
  device_id: device_id,
34
34
  refresh_token: refresh_token,
35
35
  state: state
36
- }),
36
+ },
37
37
  headers: {
38
38
  'Content-Type' => 'application/x-www-form-urlencoded'
39
39
  }
@@ -8,14 +8,14 @@ module Authkeeper
8
8
  module Requests
9
9
  module AccessToken
10
10
  def fetch_access_token(client_id:, client_secret:, code:)
11
- post(
11
+ form_post(
12
12
  path: 'token',
13
- body: URI.encode_www_form({
13
+ body: {
14
14
  grant_type: 'authorization_code',
15
15
  client_id: client_id,
16
16
  client_secret: client_secret,
17
17
  code: code
18
- }),
18
+ },
19
19
  headers: {
20
20
  'Content-Type' => 'application/x-www-form-urlencoded'
21
21
  }
@@ -23,12 +23,12 @@ module Authkeeper
23
23
  end
24
24
 
25
25
  def refresh_access_token(client_id:, client_secret:, refresh_token:)
26
- post(
26
+ form_post(
27
27
  path: 'token',
28
- body: URI.encode_www_form({
28
+ body: {
29
29
  grant_type: 'refresh_token',
30
30
  refresh_token: refresh_token
31
- }),
31
+ },
32
32
  headers: {
33
33
  'Content-Type' => 'application/x-www-form-urlencoded',
34
34
  'Authorization' => "Basic #{authorization(client_id, client_secret)}"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Authkeeper
4
- VERSION = '0.1.12'
4
+ VERSION = '0.1.13'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authkeeper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.12
4
+ version: 0.1.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bogdanov Anton