foobara-auth-http 0.0.4 → 0.0.6

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: cc7dcda6839fb8e3308d0bba11b50665978c498d747cb30ce527ce3d656d782b
4
- data.tar.gz: 4e37f052a050a488551d930ea1ddb82f3883da83b4209fc6c3819007d95e6a47
3
+ metadata.gz: 5093178b0ce509c5c5f10981172ae99ad1a1d408a73f1e0fa769e0b07bc2a473
4
+ data.tar.gz: 421cff756cbc533133f3c110298812a372a982c1823c8301b01d7b2370024e4c
5
5
  SHA512:
6
- metadata.gz: 98d257f01508c9b28f70dba5f407722fcaf761445a35479bbe3cc9c286c41a432dd378bd24e2c7607d5385339d121b564f7464ff54d676f153391b7bdfa7debd
7
- data.tar.gz: b7cfb34b6597d01bcc839567ed71075d9217222faffdfb532b1f8e1461527d6b06a50fc57ffab1da751c498788af584da26b7dea1591414f1eaed80bfab39e50
6
+ metadata.gz: 75e938c0c285d39e48972550a798c5c8e03feb0d60952e2dcf1f19796dfcde8af1fe6124ef9e3eb574be516233a0a42ab6ca6c037eb5896f08d88dbf7b987882
7
+ data.tar.gz: a972502fec1238be95c6a0f1e2b517b421d81d7843aa2a43c50119591db49581662d160908b3fefe9bce60519537a0681514861eb006ce7087e4bf2037e01f87
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [0.0.6] - 2025-05-01
2
+
3
+ - Add SetUserToAuthenticatedUser request mutator
4
+
5
+ ## [0.0.5] - 2025-05-01
6
+
7
+ - Add an ApiKeyAuthenticator
8
+
1
9
  ## [0.0.4] - 2025-04-28
2
10
 
3
11
  - Fix bug preventing refresh_token cookie from being detected
@@ -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
@@ -0,0 +1,19 @@
1
+ module Foobara
2
+ module AuthHttp
3
+ class SetUserToAuthenticatedUser < Foobara::CommandConnectors::Http::SetInputToProcResult
4
+ # TODO: move this into base class as default?
5
+ class << self
6
+ def requires_declaration_data?
7
+ false
8
+ end
9
+ end
10
+
11
+ def initialize
12
+ self.attribute_name = :user
13
+ self.input_value_proc = proc { command.authenticated_user }
14
+
15
+ super
16
+ end
17
+ end
18
+ end
19
+ 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.4
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-04-28 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,11 +63,13 @@ 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
69
70
  - src/foobara/auth_http/move_refresh_token_to_cookie.rb
70
71
  - src/foobara/auth_http/set_refresh_token_from_cookie.rb
72
+ - src/foobara/auth_http/set_user_to_authenticated_user.rb
71
73
  homepage: https://github.com/foobara/auth-http
72
74
  licenses:
73
75
  - Apache-2.0 OR MIT