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 +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/foobara/auth_http.rb +1 -0
- data/src/foobara/auth_http/api_key_authenticator.rb +49 -0
- data/src/foobara/auth_http/bearer_authenticator.rb +5 -11
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cbfea7ac24ee81f38312b0569398d94e7e7e495f27a590a85414c9ae901201ff
|
4
|
+
data.tar.gz: 297a61914942f1eb40a8a2ee7d1b690832c03f038cf2d52da4b37720fefd036c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07d8f23b097eb0958c41eee9645e82b8159356346a2a5df24e2d9ebdcb395f05eb76845c3baf0c69b14698f715e7decea5b1160eb28821d0475a1eaf9f13063b
|
7
|
+
data.tar.gz: db85cad0a02231617e84105efba347640aca0d8ce55b1a808255f6561b284164dede262d9fe6717b55da3d736b5f8ff577e7cf74c44c23897d3ae713873d0eed
|
data/CHANGELOG.md
CHANGED
data/lib/foobara/auth_http.rb
CHANGED
@@ -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
|
16
|
-
|
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
|
+
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-
|
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
|