strongroom-rails 0.5.0 → 0.6.0

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: eff1ffd8da620844d98a61ce2bdea990af1c2466269c2b4684141016b5a50aea
4
- data.tar.gz: 39cefca8d430c6de20198811d1a2bda0fb330d53f3e151a71eeac26b109a68e2
3
+ metadata.gz: 9874214d06ec5ee79f4b5dbe6aa37235c93451f0d6cd0a467eaea5cda6ea07e3
4
+ data.tar.gz: 8beaca6f9106e1659c927a7d6996fc33222de15d240081d6919fcd4c90bdaba6
5
5
  SHA512:
6
- metadata.gz: 30c068a451c3a097895d237977d4224772cab793b294f26afd666c377ee6ee2f6ec9928a0babea6627d932ad23f8d46a1bbdf0d0ec01eb51a2a60f1024bd7214
7
- data.tar.gz: efa6f25d3220d2651509b4de8a73a8e64ff3f0c053c1fe76a8b824b70ef93731bb8d96149025d29dad35eadc38dd9b233a95b8b6d9d585d716ec85170e41c179
6
+ metadata.gz: 37a61e6319cde2de30a01b6f0b1e87b4e78a3772bd8631cca99f3895db15b70d6d04b131deb59652e7f6009440dc4bf8e0aef07be054b0ace04bb2a6d8d7a40b
7
+ data.tar.gz: 636f1b27d3b89102f6b5b619dae3bb49ae44c4c24ee14c4466e279785689e3a92fdff19ff624e1de038289165f155cb76c700f2709a81728a3b1cedb55a555b5
data/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.6.0](https://github.com/seuros/strongroom/compare/strongroom-rails-v0.5.1...strongroom-rails-v0.6.0) (2026-11-30)
4
+
5
+
6
+ ### Features
7
+
8
+ * **strongroom-rails:** accept a lambda for Account model: so building the registry loads no model at boot ([#10](https://github.com/seuros/strongroom/issues/10)) ([99a71c4](https://github.com/seuros/strongroom/commit/99a71c428c5b142eeaccb60c205c67f961ef9a64))
9
+
10
+ ## [0.5.1](https://github.com/seuros/strongroom/compare/strongroom-rails-v0.5.0...strongroom-rails-v0.5.1) (2026-11-08)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * **strongroom-rails:** raise InvalidCrossOriginRequest where Rails deprecates InvalidAuthenticityToken ([#8](https://github.com/seuros/strongroom/issues/8)) ([626015d](https://github.com/seuros/strongroom/commit/626015d484b05767f41129b1600e317631b4c130))
16
+
3
17
  ## [0.5.0](https://github.com/seuros/strongroom/compare/strongroom-rails-v0.4.0...strongroom-rails-v0.5.0) (2026-11-08)
4
18
 
5
19
 
data/README.md CHANGED
@@ -53,10 +53,6 @@ Configure existing Strongroom org/app IDs, not Rails IDs.
53
53
  Use separate namespaces/bindings for users and admins; naming a namespace
54
54
  `admin` does not implement MFA or authorize an admin migration.
55
55
 
56
- Build the registry in a Rails initializer's `to_prepare` block so reloadable
57
- model classes are resolved afresh. This example deliberately leaves your
58
- binding storage and eligibility policy explicit:
59
-
60
56
  ```ruby
61
57
  Rails.application.config.to_prepare do
62
58
  client = Strongroom::Client.new(
@@ -65,7 +61,7 @@ Rails.application.config.to_prepare do
65
61
  )
66
62
 
67
63
  users = Strongroom::Rails::Account.new(
68
- client: client, table: "users", model: User,
64
+ client: client, table: "users", model: -> { User },
69
65
  # Your store must uniquely bind issuer + namespace + org + app + kernel
70
66
  # user_id to a pre-existing local record. Missing binding returns nil.
71
67
  resolve: ->(subject) { YourTrustedBindingStore.lookup(subject)&.record },
@@ -104,7 +100,8 @@ authenticate (for example an asset build without credentials) can opt out with
104
100
 
105
101
  Add additional `Account` objects to the registry for other approved namespaces.
106
102
  At most 16 are supported; names, tables and same-issuer audiences must be distinct.
107
- Pass actual model classes, never class names from parameters/configuration.
103
+ Pass a model class or a lambda returning one, never class names from
104
+ parameters/configuration. A lambda is checked against `table:` when first called.
108
105
  `register` defaults false; `register: true` needs a client configured with
109
106
  `service_endpoint:` and `service_key:` and enables `register_account` and
110
107
  `issue_verification` on the account; `issue_recovery`, `events`, `suspend`,
@@ -198,7 +195,9 @@ wildcards. An API-mode app must also provide:
198
195
  - HTTPS and a cookie scope that fits the deployment (Secure, SameSite=Lax:
199
196
  same-site subdomains work, cross-site frontends do not).
200
197
 
201
- Refusals raise `ActionController::InvalidAuthenticityToken` (422) on both paths.
198
+ Refusals raise `ActionController::InvalidAuthenticityToken` (422) on both paths;
199
+ on Rails versions that deprecate it, `ActionController::InvalidCrossOriginRequest`
200
+ (also 422). `Strongroom::Rails::Authentication::MUTATION_REFUSED` names the one in use.
202
201
  The Railtie maps `Strongroom::InvalidRequest` to 400, `Unauthorized` to 401,
203
202
  `RateLimited` to 429 and `Busy`/`ProtocolError`/`Unavailable` to 503 for
204
203
  controllers that do not `rescue_from` them.
@@ -304,7 +303,7 @@ client = Strongroom::Client.new(
304
303
  org_id: ENV.fetch("STRONGROOM_USERS_ORG_ID"), app_id: ENV.fetch("STRONGROOM_USERS_APP_ID"),
305
304
  service_endpoint: ENV.fetch("STRONGROOM_SERVICE_ENDPOINT"), service_key: ENV.fetch("STRONGROOM_USERS_SERVICE_KEY")
306
305
  )
307
- users = Strongroom::Rails::Account.new(client: client, table: "users", model: User, register: true,
306
+ users = Strongroom::Rails::Account.new(client: client, table: "users", model: -> { User }, register: true,
308
307
  resolve: ..., eligible: ...)
309
308
 
310
309
  registration = users.register_account(external_id: user.id.to_s, identity: params[:email],
@@ -3,7 +3,17 @@
3
3
  module Strongroom
4
4
  module Rails
5
5
  class Account
6
- attr_reader :client, :table, :model, :register, :cookie_name
6
+ attr_reader :client, :table, :register, :cookie_name
7
+
8
+ def self.checked_model(model, table)
9
+ unless model.is_a?(Class) && model.respond_to?(:table_name)
10
+ raise ConfigurationError, "model must be a class responding to table_name, not #{model.inspect}"
11
+ end
12
+ unless model.table_name == table
13
+ raise ConfigurationError, "#{model}.table_name is #{model.table_name.inspect}, not #{table.inspect}"
14
+ end
15
+ model
16
+ end
7
17
 
8
18
  def initialize(client:, table:, model:, resolve:, eligible:, register: false)
9
19
  raise ConfigurationError, "client must be a Strongroom::Client" unless client.is_a?(Client)
@@ -11,11 +21,10 @@ module Strongroom
11
21
  raise ConfigurationError, "table must be a lowercase SQL identifier of at most 63 characters"
12
22
  end
13
23
  raise ConfigurationError, "table #{table} is a PostgreSQL system name (pg_*)" if table.start_with?("pg_")
14
- unless model.is_a?(Class) && model.respond_to?(:table_name)
15
- raise ConfigurationError, "model must be a class responding to table_name, not #{model.inspect}"
16
- end
17
- unless model.table_name == table
18
- raise ConfigurationError, "#{model}.table_name is #{model.table_name.inspect}, not #{table.inspect}"
24
+ if model.is_a?(Module) || !model.respond_to?(:call)
25
+ self.class.checked_model(model, table)
26
+ elsif !model.respond_to?(:arity) || model.arity.positive?
27
+ raise ConfigurationError, "model callable must take no arguments and return the model class"
19
28
  end
20
29
  raise ConfigurationError, "resolve must be callable (subject -> record or nil)" unless resolve.respond_to?(:call)
21
30
  raise ConfigurationError, "eligible must be callable (record -> true)" unless eligible.respond_to?(:call)
@@ -93,6 +102,8 @@ module Strongroom
93
102
  raise Unavailable, "local principal lookup unavailable", cause: nil
94
103
  end
95
104
 
105
+ def model = @model.is_a?(Module) ? @model : self.class.checked_model(@model.call, table)
106
+
96
107
  private
97
108
 
98
109
  def registering!
@@ -9,6 +9,12 @@ module Strongroom
9
9
  extend ActiveSupport::Concern
10
10
 
11
11
  INTENT_HEADER = "HTTP_X_STRONGROOM_REQUEST"
12
+ # Rails main deprecates InvalidAuthenticityToken (no longer defined, only proxied) for InvalidCrossOriginRequest.
13
+ MUTATION_REFUSED = if ::ActionController.const_defined?(:InvalidAuthenticityToken, false)
14
+ ::ActionController::InvalidAuthenticityToken
15
+ else
16
+ ::ActionController::InvalidCrossOriginRequest
17
+ end
12
18
 
13
19
  def self.origin(value)
14
20
  NetHTTPTransport.endpoint(value)
@@ -93,7 +99,7 @@ module Strongroom
93
99
 
94
100
  def strongroom_verify_mutation!(verb)
95
101
  unless request.request_method == verb.to_s.upcase && strongroom_mutation_intended?
96
- raise ::ActionController::InvalidAuthenticityToken, "verified mutation intent required"
102
+ raise MUTATION_REFUSED, "verified mutation intent required"
97
103
  end
98
104
  end
99
105
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Strongroom
4
4
  module Rails
5
- VERSION = "0.5.0" # x-release-please-version
5
+ VERSION = "0.6.0" # x-release-please-version
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: strongroom-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seuros