foobara-auth 0.0.13 → 0.1.1
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 +9 -0
- data/src/delete_api_key.rb +46 -0
- data/src/get_api_key_summaries.rb +30 -0
- data/src/login.rb +1 -1
- data/src/types/api_key_summary.rb +14 -0
- data/src/verify_password.rb +5 -9
- data/src/verify_secret.rb +3 -7
- metadata +16 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a40375ebe8e9f9689ea358e55c4e8e00122cd84c4ddcff9a44ad0fbdd9f8138
|
4
|
+
data.tar.gz: 0a79985c2914d66cff7fc4c0f8325757b3ff4863667bcc5f957cda868063d17d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65b59bfb16f16c5ffb8c03c795977031be02d5458c472571c2781ba6b3e3173a8397c09917781a29b8696f8c7f4f3c3992030d764586cfdfbd024db55c25657c
|
7
|
+
data.tar.gz: 7b887fc6f7cc7945fd04d65b4f43d31a6f5191004f775edb863e62adf9232f921de75c075173a5392e1842e917d94450db0cee3cf1fa5a9862f81e40db3db0eb
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## [0.1.1] - 2025-10-02
|
2
|
+
|
3
|
+
- Add DeleteApiKey command
|
4
|
+
- Add GetApiKeySummary command
|
5
|
+
|
6
|
+
## [0.1.0] - 2025-08-22
|
7
|
+
|
8
|
+
- Mark as compatible with Foobara 0.1.0
|
9
|
+
|
1
10
|
## [0.0.13] - 2025-05-13
|
2
11
|
|
3
12
|
- Allow logout to work even if refresh token is deleted/invalid
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require "securerandom"
|
2
|
+
require "base64"
|
3
|
+
|
4
|
+
require_relative "build_secret"
|
5
|
+
require_relative "create_token"
|
6
|
+
|
7
|
+
module Foobara
|
8
|
+
module Auth
|
9
|
+
class DeleteApiKey < Foobara::Command
|
10
|
+
inputs do
|
11
|
+
token Types::Token, :required
|
12
|
+
end
|
13
|
+
|
14
|
+
def execute
|
15
|
+
remove_api_key_from_user
|
16
|
+
delete_token
|
17
|
+
|
18
|
+
nil
|
19
|
+
end
|
20
|
+
|
21
|
+
def load_records
|
22
|
+
super
|
23
|
+
self.user = Types::User.that_owns(token, :api_keys)
|
24
|
+
end
|
25
|
+
|
26
|
+
attr_accessor :user
|
27
|
+
|
28
|
+
# should Foobara do this automatically? Or at least support it? Similar to CASCADE in SQL
|
29
|
+
def remove_api_key_from_user
|
30
|
+
api_keys = user.api_keys
|
31
|
+
|
32
|
+
if api_keys.include?(token)
|
33
|
+
user.api_keys = api_keys - [token]
|
34
|
+
else
|
35
|
+
# :nocov:
|
36
|
+
raise "User has no such api key"
|
37
|
+
# :nocov:
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def delete_token
|
42
|
+
token.hard_delete!
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Foobara
|
2
|
+
module Auth
|
3
|
+
class GetApiKeySummaries < Foobara::Command
|
4
|
+
inputs do
|
5
|
+
user Types::User, :required
|
6
|
+
end
|
7
|
+
|
8
|
+
result [Types::ApiKeySummary]
|
9
|
+
|
10
|
+
def execute
|
11
|
+
build_summaries
|
12
|
+
|
13
|
+
summaries
|
14
|
+
end
|
15
|
+
|
16
|
+
attr_accessor :api_keys, :summaries
|
17
|
+
|
18
|
+
def build_summaries
|
19
|
+
self.summaries = user.api_keys.map do |api_key|
|
20
|
+
Types::ApiKeySummary.new(
|
21
|
+
token_id: api_key.id,
|
22
|
+
state: api_key.state,
|
23
|
+
expires_at: api_key.expires_at,
|
24
|
+
created_at: api_key.created_at
|
25
|
+
)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/src/login.rb
CHANGED
@@ -53,7 +53,7 @@ module Foobara
|
|
53
53
|
rescue Halt
|
54
54
|
# I'm a bit nervous about rescuing Halt and clearing the errors, but I'm more nervous bout
|
55
55
|
# introducing a #run_subcommand method.
|
56
|
-
if error_collection.size == 1 && error_collection.
|
56
|
+
if error_collection.size == 1 && error_collection.first.is_a?(FindUser::UserNotFoundError) &&
|
57
57
|
username_or_email.include?("@")
|
58
58
|
error_collection.clear
|
59
59
|
self.user_to_login = run_subcommand!(FindUser, email: username_or_email)
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Foobara
|
2
|
+
module Auth
|
3
|
+
module Types
|
4
|
+
class ApiKeySummary < Foobara::Model
|
5
|
+
attributes do
|
6
|
+
token_id :string, :required
|
7
|
+
state :token_state, :required, default: :needs_approval
|
8
|
+
expires_at :datetime, :allow_nil
|
9
|
+
created_at :datetime, :required
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/src/verify_password.rb
CHANGED
@@ -16,21 +16,17 @@ module Foobara
|
|
16
16
|
# TODO: result in error if no password set yet?
|
17
17
|
check_for_valid_password
|
18
18
|
|
19
|
-
|
19
|
+
is_valid_password
|
20
20
|
end
|
21
21
|
|
22
|
-
attr_accessor :
|
23
|
-
|
24
|
-
def valid_password?
|
25
|
-
!!valid_password
|
26
|
-
end
|
22
|
+
attr_accessor :is_valid_password
|
27
23
|
|
28
24
|
def check_for_valid_password
|
29
25
|
hashed_secret = user.password_secret.hashed_secret
|
30
26
|
|
31
|
-
self.
|
32
|
-
|
33
|
-
|
27
|
+
self.is_valid_password = if hashed_secret
|
28
|
+
run_subcommand!(VerifySecret, secret: plaintext_password, hashed_secret:)
|
29
|
+
end
|
34
30
|
end
|
35
31
|
end
|
36
32
|
end
|
data/src/verify_secret.rb
CHANGED
@@ -13,17 +13,13 @@ module Foobara
|
|
13
13
|
def execute
|
14
14
|
verify_secret_against_hashed_secret
|
15
15
|
|
16
|
-
|
16
|
+
is_verified
|
17
17
|
end
|
18
18
|
|
19
|
-
attr_accessor :
|
20
|
-
|
21
|
-
def verified?
|
22
|
-
!!verified
|
23
|
-
end
|
19
|
+
attr_accessor :is_verified
|
24
20
|
|
25
21
|
def verify_secret_against_hashed_secret
|
26
|
-
self.
|
22
|
+
self.is_verified = Argon2::Password.verify_password(secret, hashed_secret)
|
27
23
|
end
|
28
24
|
end
|
29
25
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foobara-auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miles Georgi
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: argon2
|
@@ -41,16 +41,22 @@ dependencies:
|
|
41
41
|
name: foobara
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
|
-
- - "
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.1.1
|
47
|
+
- - "<"
|
45
48
|
- !ruby/object:Gem::Version
|
46
|
-
version: 0.0
|
49
|
+
version: 2.0.0
|
47
50
|
type: :runtime
|
48
51
|
prerelease: false
|
49
52
|
version_requirements: !ruby/object:Gem::Requirement
|
50
53
|
requirements:
|
51
|
-
- - "
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 0.1.1
|
57
|
+
- - "<"
|
52
58
|
- !ruby/object:Gem::Version
|
53
|
-
version: 0.0
|
59
|
+
version: 2.0.0
|
54
60
|
email:
|
55
61
|
- azimux@gmail.com
|
56
62
|
executables: []
|
@@ -73,13 +79,16 @@ files:
|
|
73
79
|
- src/create_role.rb
|
74
80
|
- src/create_token.rb
|
75
81
|
- src/create_user.rb
|
82
|
+
- src/delete_api_key.rb
|
76
83
|
- src/find_user.rb
|
84
|
+
- src/get_api_key_summaries.rb
|
77
85
|
- src/login.rb
|
78
86
|
- src/logout.rb
|
79
87
|
- src/refresh_login.rb
|
80
88
|
- src/register.rb
|
81
89
|
- src/reset_password.rb
|
82
90
|
- src/set_password.rb
|
91
|
+
- src/types/api_key_summary.rb
|
83
92
|
- src/types/role.rb
|
84
93
|
- src/types/secret.rb
|
85
94
|
- src/types/token.rb
|
@@ -112,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
121
|
- !ruby/object:Gem::Version
|
113
122
|
version: '0'
|
114
123
|
requirements: []
|
115
|
-
rubygems_version: 3.6.
|
124
|
+
rubygems_version: 3.6.9
|
116
125
|
specification_version: 4
|
117
126
|
summary: Provides various auth domain commands and models
|
118
127
|
test_files: []
|