standard_id 0.14.3 → 0.14.4

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: 3ef63474df3107460650e529f2c8cf46ec3b0998f81db90ece5cf37d95ec14fc
4
- data.tar.gz: 3c0e147ce91c2442d05157507d088aa8f1a6fcb52b7e38c4e15b2d5cb6da9fde
3
+ metadata.gz: 47ce66e4e4b242fd96a90cda7b20a9316e31642551ebe6c94ae660336f8f0b2c
4
+ data.tar.gz: a1a6d6f746f2ef0590aec0b5d6c4cc51472e04030af53e30d8546495d2556f03
5
5
  SHA512:
6
- metadata.gz: 0571fe2ae8b0e429f8c9ab8d3f7f73e475e1395297d392460fce1d7db0d75b880baeebbd7e34befbba7e58fc37684255902ea1358b5bbed2be6b6e2a29489c36
7
- data.tar.gz: 791d1b6618bd054da2e57b2ee7f626eb60af647070b1d075ceb1f274e92ec4b3912b601ec076af3ad81357f957c1dfa460810d448a628c93c1791b299b127be2
6
+ metadata.gz: f323ce02474f8d4fc98a8aa4466616f15e58b9a5f6174336c91c0f9bc02c22e95862909963d0470271b49dc588fb0abcfcd2434c17a7ece79952d7547ed81ddf
7
+ data.tar.gz: 03a24d819ad4f699be3d97ce26e8dcf04873b373ff55c03e31f0de475a014198053a1927bf6539de40c0398855490be01ea4bc77dbe093d1f381f67eddfb8608
@@ -0,0 +1,7 @@
1
+ class AddTargetCreatedAtIndexToCodeChallenges < ActiveRecord::Migration[8.0]
2
+ def change
3
+ add_index :standard_id_code_challenges,
4
+ [:realm, :channel, :target, :created_at],
5
+ name: "index_code_challenges_on_target_created_at"
6
+ end
7
+ end
@@ -28,18 +28,30 @@ module StandardId
28
28
  protected
29
29
 
30
30
  def create_challenge!(username)
31
- code = generate_otp_code
31
+ ActiveRecord::Base.transaction do
32
+ invalidate_active_challenges!(username)
33
+
34
+ code = generate_otp_code
35
+
36
+ StandardId::CodeChallenge.create!(
37
+ realm: "authentication",
38
+ channel: connection_type,
39
+ target: username,
40
+ code: code,
41
+ expires_at: StandardId.config.passwordless.code_ttl.seconds.from_now,
42
+ ip_address: StandardId::Utils::IpNormalizer.normalize(request.remote_ip),
43
+ user_agent: request.user_agent
44
+ )
45
+ end
46
+ end
32
47
 
33
- cc = StandardId::CodeChallenge.create!(
34
- realm: "authentication",
35
- channel: connection_type,
36
- target: username,
37
- code: code,
38
- expires_at: StandardId.config.passwordless.code_ttl.seconds.from_now,
39
- ip_address: StandardId::Utils::IpNormalizer.normalize(request.remote_ip),
40
- user_agent: request.user_agent
41
- )
42
- cc
48
+ # Uses update_all for a single UPDATE statement (no N+1). This bypasses
49
+ # ActiveRecord callbacks intentionally — CodeChallenge has no after-save
50
+ # hooks today. If callbacks are added to CodeChallenge#use!, revisit this.
51
+ def invalidate_active_challenges!(username)
52
+ StandardId::CodeChallenge.active
53
+ .where(realm: "authentication", channel: connection_type, target: username)
54
+ .update_all(used_at: Time.current)
43
55
  end
44
56
 
45
57
  def generate_otp_code
@@ -200,11 +200,10 @@ module StandardId
200
200
  end
201
201
 
202
202
  def find_active_challenge
203
- StandardId::CodeChallenge.active.find_by(
204
- realm: "authentication",
205
- channel: @channel,
206
- target: @target
207
- )
203
+ StandardId::CodeChallenge.active
204
+ .where(realm: "authentication", channel: @channel, target: @target)
205
+ .order(created_at: :desc)
206
+ .first
208
207
  end
209
208
 
210
209
  # NOTE: The update! here can raise ActiveRecord::RecordInvalid, which is
@@ -1,3 +1,3 @@
1
1
  module StandardId
2
- VERSION = "0.14.3"
2
+ VERSION = "0.14.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: standard_id
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.3
4
+ version: 0.14.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jaryl Sim
@@ -205,6 +205,7 @@ files:
205
205
  - db/migrate/20260311000000_add_provider_to_standard_id_identifiers.rb
206
206
  - db/migrate/20260311100000_create_standard_id_refresh_tokens.rb
207
207
  - db/migrate/20260311100001_add_nullify_to_refresh_token_previous_token_fk.rb
208
+ - db/migrate/20260414200000_add_target_created_at_index_to_code_challenges.rb
208
209
  - lib/generators/standard_id/install/install_generator.rb
209
210
  - lib/generators/standard_id/install/templates/standard_id.rb
210
211
  - lib/standard_config.rb