foobara-auth-http 0.0.4 → 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: cc7dcda6839fb8e3308d0bba11b50665978c498d747cb30ce527ce3d656d782b
4
- data.tar.gz: 4e37f052a050a488551d930ea1ddb82f3883da83b4209fc6c3819007d95e6a47
3
+ metadata.gz: cbfea7ac24ee81f38312b0569398d94e7e7e495f27a590a85414c9ae901201ff
4
+ data.tar.gz: 297a61914942f1eb40a8a2ee7d1b690832c03f038cf2d52da4b37720fefd036c
5
5
  SHA512:
6
- metadata.gz: 98d257f01508c9b28f70dba5f407722fcaf761445a35479bbe3cc9c286c41a432dd378bd24e2c7607d5385339d121b564f7464ff54d676f153391b7bdfa7debd
7
- data.tar.gz: b7cfb34b6597d01bcc839567ed71075d9217222faffdfb532b1f8e1461527d6b06a50fc57ffab1da751c498788af584da26b7dea1591414f1eaed80bfab39e50
6
+ metadata.gz: 07d8f23b097eb0958c41eee9645e82b8159356346a2a5df24e2d9ebdcb395f05eb76845c3baf0c69b14698f715e7decea5b1160eb28821d0475a1eaf9f13063b
7
+ data.tar.gz: db85cad0a02231617e84105efba347640aca0d8ce55b1a808255f6561b284164dede262d9fe6717b55da3d736b5f8ff577e7cf74c44c23897d3ae713873d0eed
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## [0.0.5] - 2025-05-01
2
+
3
+ - Add an ApiKeyAuthenticator
4
+
1
5
  ## [0.0.4] - 2025-04-28
2
6
 
3
7
  - 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
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.5
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,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