authkeeper 0.1.12 → 0.1.14

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: f81527eb51e201f297210d2bc14ac073bcbdc24819d401eb5d1019db8b19349e
4
+ data.tar.gz: 9d40216d7d9f835854fee8d8f7aa02cfd216c7d13fe784fd2d4199a86208afc0
5
5
  SHA512:
6
- metadata.gz: 87bbb1e064c3895257a4e52f7562fd01c4bea1fec9bc42a9d09672990af592105a598b26e89a9edfba421704f06443e33f3a653f61690b419744198cd780c8b1
7
- data.tar.gz: 5e4390d669b30a5bab62ead49016f407b201b7c2c5c97240ddfe6b2c266ee110bbd203e93d903dc53904616ce973ae6f4b40768e7a53bd16084a2a882622042b
6
+ metadata.gz: a663f043f533de2b93f07d605d8fb2e0f303bdcda51b49f7c3c59e3531323c86ede88be5b71e4e510a2046843f579586645ebbb727a3eda9dced0588482e5897
7
+ data.tar.gz: 1b379e30dcc3838f5461a0e7ed83f938beed89399671473a7f8a47ff42858bdc2ec72f1fbf1eeb7583e2bf3a3f3f5d78638eba8f41b66bf1e2fea27077a0da91
@@ -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)}"
@@ -14,7 +14,7 @@ module Authkeeper
14
14
  private
15
15
 
16
16
  def set_current_user
17
- return find_user if Authkeeper.configuration.current_user_cache_minutes.nil?
17
+ return find_authkeeper_user if Authkeeper.configuration.current_user_cache_minutes.nil?
18
18
 
19
19
  access_token = cookies_token.presence || bearer_token.presence || params_token
20
20
  return unless access_token
@@ -28,13 +28,13 @@ module Authkeeper
28
28
  expires_in: Authkeeper.configuration.current_user_cache_minutes.minutes,
29
29
  race_condition_ttl: 10.seconds
30
30
  ) do
31
- find_user
31
+ find_authkeeper_user
32
32
  current_user&.id
33
33
  end
34
34
  @current_user ||= User.find_by(id: user_id)
35
35
  end
36
36
 
37
- def find_user
37
+ def find_authkeeper_user
38
38
  access_token = cookies_token.presence || bearer_token.presence || params_token
39
39
  return unless access_token
40
40
 
@@ -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.14'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
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.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bogdanov Anton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-12-24 00:00:00.000000000 Z
11
+ date: 2025-12-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails