foobara-auth 0.0.10 → 0.0.12

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: 45cdb3b28235c09c136eb81a09662517dd017afef86cb5fd11b1c966a264685d
4
- data.tar.gz: 65b323560c3469fa6b1c29e20d39f4ecf4c6e42011da3a7244876863f87057ab
3
+ metadata.gz: 371e579335275b2c6d8d695aea7b14784f6ecf95d1df4742b38eb251ba941a6a
4
+ data.tar.gz: 12354ce1c4b44cdb8ce1c398b7334ac6ce0f6a4a3ee619e698b5c94e114df528
5
5
  SHA512:
6
- metadata.gz: 48db1658d6fa78ae0cfe733c7bb58288519399311007851d03c5253f2ebd44f089027820f788c1bfe7af012372520639a56594471d6f50269e75e75c47c884a7
7
- data.tar.gz: c6c486c5f4a408177e6a534169bea9d0a77068d8208ed99f5c4217ca37d6f247ffc00743041ff4306f858c5963592ebf9bbd857b6422412a8618cb4157d29df6
6
+ metadata.gz: 7d79b81bd382733037b66f464552e5401c69801355bc78c00354f22ca60b8db43d4066b012476a1b7bcdd854d03b39e854847b6cbf5bdc39543f7dc80e832cac
7
+ data.tar.gz: 2cbd1f530b358e94eb0dd161640828e69473ede06f9d0d56204ece3ecc17efc974a3b283b902344709c2932077b777c9a400357b8c712d9b31e0df8e5bd79faa
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [0.0.12] - 2025-05-05
2
+
3
+ - Do not explode when refresh token doesn't exist
4
+
5
+ ## [0.0.11] - 2025-05-01
6
+
7
+ - Add a runtime error when an api key doesn't exist
8
+
1
9
  ## [0.0.10] - 2025-04-28
2
10
 
3
11
  - Add AuthenticateWithApiKey command
@@ -4,10 +4,15 @@ module Foobara
4
4
  module Auth
5
5
  class AuthenticateWithApiKey < Foobara::Command
6
6
  class InvalidApiKeyError < Foobara::RuntimeError
7
- context api_key_id: :string
7
+ context({})
8
8
  message "Invalid api key"
9
9
  end
10
10
 
11
+ class ApiKeyDoesNotExistError < Foobara::RuntimeError
12
+ context({})
13
+ message "No such key"
14
+ end
15
+
11
16
  depends_on VerifyToken
12
17
  depends_on_entities Types::Token
13
18
 
@@ -37,13 +42,15 @@ module Foobara
37
42
 
38
43
  def load_api_key_record
39
44
  self.api_key_record = Types::Token.load(api_key_id)
45
+ rescue Foobara::Entity::NotFoundError
46
+ add_runtime_error(ApiKeyDoesNotExistError)
40
47
  end
41
48
 
42
49
  def verify_api_key
43
50
  valid = run_subcommand!(VerifyToken, token_string: api_key)
44
51
 
45
52
  unless valid[:verified]
46
- add_runtime_error(InvalidApiKeyError.new(context: { api_key_id: }))
53
+ add_runtime_error(InvalidApiKeyError)
47
54
  end
48
55
  end
49
56
 
data/src/create_user.rb CHANGED
@@ -12,6 +12,9 @@ module Foobara
12
12
 
13
13
  depends_on SetPassword
14
14
 
15
+ possible_input_error :username, :already_in_use
16
+ possible_input_error :email, :already_in_use
17
+
15
18
  def execute
16
19
  create_user
17
20
 
@@ -22,8 +25,27 @@ module Foobara
22
25
  user
23
26
  end
24
27
 
28
+ def validate
29
+ validate_username_is_unique
30
+ if email
31
+ validate_email_is_unique
32
+ end
33
+ end
34
+
25
35
  attr_accessor :user
26
36
 
37
+ def validate_username_is_unique
38
+ if Types::User.find_by(username:)
39
+ add_input_error(input: :username, symbol: :already_in_use)
40
+ end
41
+ end
42
+
43
+ def validate_email_is_unique
44
+ if Types::User.find_by(email:)
45
+ add_input_error(input: :email, symbol: :already_in_use)
46
+ end
47
+ end
48
+
27
49
  def create_user
28
50
  inputs = self.inputs.except(:user_id, :plaintext_password)
29
51
 
data/src/refresh_login.rb CHANGED
@@ -2,7 +2,7 @@ module Foobara
2
2
  module Auth
3
3
  class RefreshLogin < Foobara::Command
4
4
  class InvalidRefreshTokenError < Foobara::RuntimeError
5
- context refresh_token_id: :string
5
+ context({})
6
6
  message "Invalid refresh token"
7
7
  end
8
8
 
@@ -44,13 +44,15 @@ module Foobara
44
44
 
45
45
  def load_refresh_token_record
46
46
  self.refresh_token_record = Types::Token.load(refresh_token_id)
47
+ rescue Foobara::Entity::NotFoundError
48
+ add_runtime_error(InvalidRefreshTokenError.new)
47
49
  end
48
50
 
49
51
  def verify_refresh_token
50
52
  valid = run_subcommand!(VerifyToken, token_string: refresh_token)
51
53
 
52
54
  unless valid[:verified]
53
- add_runtime_error(InvalidRefreshTokenError.new(context: { refresh_token_id: }))
55
+ add_runtime_error(InvalidRefreshTokenError.new)
54
56
  end
55
57
  end
56
58
 
@@ -10,7 +10,7 @@ module Foobara
10
10
 
11
11
  result do
12
12
  verified :boolean, :required
13
- failure_reason :string, :allow_nil, one_of: %w[invalid expired cannot_verify]
13
+ failure_reason :string, :allow_nil, one_of: ["invalid", "expired", "cannot_verify"]
14
14
  payload :associative_array, :allow_nil
15
15
  headers :associative_array, :allow_nil
16
16
  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.0.10
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-05-01 00:00:00.000000000 Z
10
+ date: 2025-05-05 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: argon2