foobara-auth-http 0.0.3 → 0.0.5

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: 215085501258008264243a87c8e01db2e9322ea7f33c8cf22553659ff2524d06
4
- data.tar.gz: 769f8c1c3cb67b6fcb6c40d65f85ce1c494fc6c1238d6a606e18f7b35423de19
3
+ metadata.gz: cbfea7ac24ee81f38312b0569398d94e7e7e495f27a590a85414c9ae901201ff
4
+ data.tar.gz: 297a61914942f1eb40a8a2ee7d1b690832c03f038cf2d52da4b37720fefd036c
5
5
  SHA512:
6
- metadata.gz: caa515d8a6fbac87718425dbcacd4c3f4a672ec40746d62b2af42b32b89190f09752a0e0f632c02bedeb53737e734f4c2c6feb8173f1e09d5d6ba6c02f0f9e89
7
- data.tar.gz: d008b9ffd7f400931c4a3360370f438d2148e73834b663d996d9ba0cafb83bf0de80b55acfe66beb5b35c556ccd7c534aeb2f07b1845930958a66c60896d9a49
6
+ metadata.gz: 07d8f23b097eb0958c41eee9645e82b8159356346a2a5df24e2d9ebdcb395f05eb76845c3baf0c69b14698f715e7decea5b1160eb28821d0475a1eaf9f13063b
7
+ data.tar.gz: db85cad0a02231617e84105efba347640aca0d8ce55b1a808255f6561b284164dede262d9fe6717b55da3d736b5f8ff577e7cf74c44c23897d3ae713873d0eed
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [0.0.5] - 2025-05-01
2
+
3
+ - Add an ApiKeyAuthenticator
4
+
5
+ ## [0.0.4] - 2025-04-28
6
+
7
+ - Fix bug preventing refresh_token cookie from being detected
8
+
1
9
  ## [0.0.3] - 2025-04-25
2
10
 
3
11
  - Add BearerToken.load_user
@@ -9,6 +9,7 @@ module Foobara
9
9
  class << self
10
10
  def install!
11
11
  CommandConnectors::Http.register_authenticator(BearerAuthenticator)
12
+ CommandConnectors::Http.register_authenticator(ApiKeyAuthenticator)
12
13
  end
13
14
  end
14
15
  end
@@ -0,0 +1,49 @@
1
+ module Foobara
2
+ module AuthHttp
3
+ class ApiKeyAuthenticator < CommandConnector::Authenticator
4
+ class << self
5
+ def load_user(&block)
6
+ new(load_user: block)
7
+ end
8
+ end
9
+
10
+ def initialize(load_user: nil, **)
11
+ if load_user
12
+ @load_user = load_user
13
+ end
14
+
15
+ super(
16
+ symbol: :api_key,
17
+ explanation: "Expects an api key to be passed in the x-api-key header",
18
+ **
19
+ )
20
+ end
21
+
22
+ def applicable?(request)
23
+ request.headers.key?("x-api-key")
24
+ end
25
+
26
+ def block
27
+ @block ||= begin
28
+ load_user_block = @load_user
29
+
30
+ proc do
31
+ api_key = headers["x-api-key"]
32
+
33
+ outcome = Foobara::Auth::AuthenticateWithApiKey.run(api_key:)
34
+
35
+ if outcome.success?
36
+ user, credential = outcome.result
37
+
38
+ if load_user_block
39
+ user = load_user_block.call(user.id)
40
+ end
41
+
42
+ [user, credential]
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -9,19 +9,13 @@ module Foobara
9
9
 
10
10
  def initialize(load_user: nil, **)
11
11
  @load_user = load_user || ->(user_id) { Auth::FindUser.run!(id: user_id) }
12
- super(**)
12
+ super(symbol: :bearer,
13
+ explanation: "Expects an access token in authorization header in format of: Bearer <token>",
14
+ **)
13
15
  end
14
16
 
15
- def symbol
16
- :bearer
17
- end
18
-
19
- def explanation
20
- @explanation ||= "Expects an access token in authorization header in format of: Bearer <token>"
21
- end
22
-
23
- def authenticate(request)
24
- request.instance_exec(&to_proc)
17
+ def applicable?(request)
18
+ request.headers.key?("authorization")
25
19
  end
26
20
 
27
21
  def block
@@ -11,7 +11,7 @@ module Foobara
11
11
  def initialize(header_name = "X-Access-Token", header_value = nil)
12
12
  super()
13
13
 
14
- self.header_name = header_name
14
+ self.header_name = header_name.to_s
15
15
  self.header_value = header_value
16
16
  end
17
17
  end
@@ -11,8 +11,8 @@ module Foobara
11
11
  def initialize(attribute_name = :access_token, header_name = "X-Access-Token")
12
12
  super()
13
13
 
14
- self.attribute_name = attribute_name
15
- self.header_name = header_name
14
+ self.attribute_name = attribute_name.to_sym
15
+ self.header_name = header_name.to_s
16
16
  end
17
17
  end
18
18
  end
@@ -11,8 +11,8 @@ module Foobara
11
11
  def initialize(attribute_name = :refresh_token, cookie_name = attribute_name, **cookie_opts)
12
12
  super()
13
13
 
14
- self.attribute_name = attribute_name
15
- self.cookie_name = cookie_name
14
+ self.attribute_name = attribute_name.to_sym
15
+ self.cookie_name = cookie_name.to_s
16
16
  self.cookie_opts = {
17
17
  httponly: true,
18
18
  path: "/run/Foobara/Auth/",
@@ -11,8 +11,8 @@ module Foobara
11
11
  def initialize(attribute_name = :refresh_token, cookie_name = attribute_name)
12
12
  super()
13
13
 
14
- self.attribute_name = attribute_name
15
- self.cookie_name = cookie_name
14
+ self.attribute_name = attribute_name.to_sym
15
+ self.cookie_name = cookie_name.to_s
16
16
  end
17
17
  end
18
18
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foobara-auth-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 1980-01-02 00:00:00.000000000 Z
10
+ date: 2025-05-01 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: foobara
@@ -63,6 +63,7 @@ files:
63
63
  - LICENSE.txt
64
64
  - README.md
65
65
  - lib/foobara/auth_http.rb
66
+ - src/foobara/auth_http/api_key_authenticator.rb
66
67
  - src/foobara/auth_http/bearer_authenticator.rb
67
68
  - src/foobara/auth_http/clear_access_token_header.rb
68
69
  - src/foobara/auth_http/move_access_token_to_header.rb
@@ -90,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
91
  - !ruby/object:Gem::Version
91
92
  version: '0'
92
93
  requirements: []
93
- rubygems_version: 3.6.8
94
+ rubygems_version: 3.6.2
94
95
  specification_version: 4
95
96
  summary: Contains convenience classes/methods for using Foobara::Auth over HTTP
96
97
  test_files: []