strongroom-rails 0.3.0 → 0.5.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: 2313700e0514a62dbf3f58e5f541e0c4421f4c034a8220840cd9ca243d05b816
4
- data.tar.gz: 5530d843f7630a021488e36bcc230bdfd9d1137f3aec6c5a1dd8d233c3a9b09f
3
+ metadata.gz: eff1ffd8da620844d98a61ce2bdea990af1c2466269c2b4684141016b5a50aea
4
+ data.tar.gz: 39cefca8d430c6de20198811d1a2bda0fb330d53f3e151a71eeac26b109a68e2
5
5
  SHA512:
6
- metadata.gz: 5b77a81722924260a13456a6416012c2670dafe0360cb8932f21c8fd3250301a50564fd7d86e7c26425e741b5fd781a08b694a812357afece92dec857570b881
7
- data.tar.gz: fce5256ee8f35e3f44e70165c0615a0d5c3a0ddc61b05d5b976cf7918368f425d0b0ef026d7009fb1c7a44a733bb0b36f8849b56eda5ee73b5cb32c2b25b4127
6
+ metadata.gz: 30c068a451c3a097895d237977d4224772cab793b294f26afd666c377ee6ee2f6ec9928a0babea6627d932ad23f8d46a1bbdf0d0ec01eb51a2a60f1024bd7214
7
+ data.tar.gz: efa6f25d3220d2651509b4de8a73a8e64ff3f0c053c1fe76a8b824b70ef93731bb8d96149025d29dad35eadc38dd9b233a95b8b6d9d585d716ec85170e41c179
data/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.5.0](https://github.com/seuros/strongroom/compare/strongroom-rails-v0.4.0...strongroom-rails-v0.5.0) (2026-11-08)
4
+
5
+
6
+ ### Features
7
+
8
+ * Client#audience_token relays a session to the kernel's token route; token issuers may be any URI ([670dc51](https://github.com/seuros/strongroom/commit/670dc51b289c79f907214213a88f5fae85bb3bdf))
9
+
10
+ ## [0.4.0](https://github.com/seuros/strongroom/compare/strongroom-rails-v0.3.0...strongroom-rails-v0.4.0) (2026-10-26)
11
+
12
+
13
+ ### Features
14
+
15
+ * add account suspension and session revocation, service imports with conditional password replacement and in-daemon pruning; recover only verified identities ([be52bd1](https://github.com/seuros/strongroom/commit/be52bd1654b9f104aa8e82eb2129d0751a62f3d1))
16
+
3
17
  ## [0.3.0](https://github.com/seuros/strongroom/compare/strongroom-rails-v0.2.0...strongroom-rails-v0.3.0) (2026-10-25)
4
18
 
5
19
 
data/README.md CHANGED
@@ -3,8 +3,8 @@
3
3
  Rails adapter for [Strongroom](https://github.com/seuros/strongroom), a Postgres-first authentication kernel
4
4
  that acts as your application's security coprocessor: Rails never sees password
5
5
  hashes or session secrets. Registration and recovery links go through the
6
- kernel's service API from your server; MFA, JWT minting, mail and automatic
7
- routes are deliberately absent.
6
+ kernel's service API from your server; MFA, mail and automatic routes are
7
+ deliberately absent, and the only JWTs are the kernel's own audience tokens.
8
8
 
9
9
  > **Status: pre-production.** Strongroom has not been audited and is not approved
10
10
  > for production traffic or real credential imports.
@@ -107,8 +107,10 @@ At most 16 are supported; names, tables and same-issuer audiences must be distin
107
107
  Pass actual model classes, never class names from parameters/configuration.
108
108
  `register` defaults false; `register: true` needs a client configured with
109
109
  `service_endpoint:` and `service_key:` and enables `register_account` and
110
- `issue_verification` on the account; `issue_recovery` and `events` need only
111
- the service key. The gem still installs no route.
110
+ `issue_verification` on the account; `issue_recovery`, `events`, `suspend`,
111
+ `reinstate` and `revoke_sessions` need only the service key, and
112
+ `import_account` and `replace_imported_password` a namespace with
113
+ `import = true`. The gem still installs no route.
112
114
 
113
115
  Controllers opt in explicitly and keep their own frontend response contract:
114
116
 
@@ -369,7 +371,8 @@ verifies the address.
369
371
  `Strongroom::Event`s (`Provision`, `Register`, `RegistrationCancel`,
370
372
  `VerificationIssue`, `IdentityVerify`, `PasswordHashUpgrade`,
371
373
  `PasswordReplace`, `Revoke`, `RecoveryIssue`, `RecoveryComplete`,
372
- `PasswordChange`); keep `page.next` and pass it as `after:`.
374
+ `PasswordChange`, `AccountSuspend`, `AccountReinstate`); keep `page.next`
375
+ and pass it as `after:`.
373
376
  `next` is `nil` for an empty page: ask again later with the cursor you have.
374
377
  `page.oldest_at` is the oldest event the kernel still holds; if your last
375
378
  event is older, retention pruned events you never read. `Strongroom::CursorAhead`
@@ -383,6 +386,39 @@ Service-key refusals raise `Strongroom::ProtocolError` (a deployment error, not
383
386
  a user's), rate limits `Strongroom::RateLimited`/`Busy` with `retry_after`. The
384
387
  Railtie maps `Conflict`s to 409, `InvalidPassword` to 422 and `NotFound` to 404.
385
388
 
389
+ ## Account control and imports
390
+
391
+ On the client of any keyed namespace:
392
+
393
+ - `suspend(user_id:)` suspends the user's account in the namespace's org: every
394
+ session it holds there ends, its verification and recovery links stop
395
+ working, and nothing authenticates until `reinstate(user_id:)`, which leaves
396
+ those sessions and links ended. Both return a `Strongroom::AccountChange`
397
+ (`state`, `changed`: false for a repeat, `revoked_sessions`).
398
+ - `revoke_sessions(user_id:)` ends every live session of the user in the org
399
+ ("sign out everywhere") and returns how many ended.
400
+ - All three raise `Strongroom::NotFound` for a user outside the namespace,
401
+ `Strongroom::AccountDisabled` (suspension and reinstatement) for a disabled
402
+ account, and `Strongroom::Busy` while one of the user's sessions is being
403
+ rotated or logged out: retry, nothing changed.
404
+
405
+ With `import = true` on the namespace:
406
+
407
+ - `import_account(source:, external_id:, identity:, password_hash:,
408
+ account_state:, grant_state:, identity_state:, credential_state:,
409
+ mfa_required:)` imports an account with a pre-hashed password, as
410
+ `strongroom-admin provision` does, and returns a `Strongroom::Import`
411
+ (`user_id`, `identity_id`, `credential_id`, `created`: false for a replay).
412
+ Every state is explicit. It raises `Strongroom::BindingConflict`,
413
+ `Strongroom::IdentityTaken` or `Strongroom::InvalidRequest`.
414
+ - `replace_imported_password(source:, external_id:, expected_password_hash:,
415
+ password_hash:)` replaces that account's password only while it still holds
416
+ `expected_password_hash`, and returns a `Strongroom::PasswordReplacement`
417
+ (`status` `"replaced"` or `"unchanged"`). Once the kernel owns the password
418
+ (a login upgraded the hash, a recovery or password change replaced it), it
419
+ raises `Strongroom::CredentialChanged` and changes nothing: stop sending
420
+ hashes for that account.
421
+
386
422
  ## Password change and recovery
387
423
 
388
424
  ### Changing a password
@@ -445,6 +481,8 @@ class RecoveryMailer < ApplicationMailer
445
481
  mail(to: params.fetch(:email), subject: "Choose a new password")
446
482
  rescue Strongroom::NotFound
447
483
  # No usable account holds the address: without `mail`, nothing is sent.
484
+ rescue Strongroom::IdentityUnverified
485
+ # Registered, never verified: cancel that registration instead (see below).
448
486
  end
449
487
  end
450
488
  ```
@@ -453,8 +491,9 @@ end
453
491
  `Strongroom::RecoveryToken` redacted everywhere and never a session credential;
454
492
  `expires_at`, by default 30 minutes away; `user_id`). Earlier links of that
455
493
  address stop working. It raises `Strongroom::NotFound` when no usable account
456
- holds the address in the namespace: answer your users the same way either way,
457
- or the form tells anyone which addresses have accounts. If the token must
494
+ holds the address in the namespace, and `Strongroom::IdentityUnverified` when
495
+ the address was registered but never verified: answer your users the same way
496
+ in every case, or the form tells anyone which addresses have accounts. If the token must
458
497
  travel through a job after all, only in an argument your own
459
498
  `ActiveJob::Serializers::ObjectSerializer` encrypts.
460
499
 
@@ -471,16 +510,34 @@ const reply = await fetch(`${STRONGROOM_ORIGIN}/accounts/users/recovery`, {
471
510
  // usable; 400 {"error": "invalid_token", "reason": "invalid" | "expired"}; 503: retry
472
511
  ```
473
512
 
474
- A completed recovery sets the new password, ends every session of the user in
475
- the org (in every app) and their other recovery links, and verifies an address
476
- that was never verified: following the link proved the mailbox. Send the
477
- person to your sign-in page afterwards. A second use of the link answers
513
+ A completed recovery sets the new password and ends every session of the user
514
+ in the org (in every app) and their other recovery links. Send the person to
515
+ your sign-in page afterwards. A second use of the link answers
478
516
  `invalid_token`. Links belong to the address across every app of the org.
479
517
 
480
- Do not offer recovery for an address whose registration is still unverified:
481
- the owner would inherit the account whoever registered it prepared (your
482
- records for that `external_id`), and `cancel_registration` refuses it once
483
- verified. Cancel such a registration and let the owner register afresh.
518
+ Only verified addresses recover: anybody can register an address, and its
519
+ owner would inherit the account whoever registered it prepared (your records
520
+ for that `external_id`). On `Strongroom::IdentityUnverified`, cancel that
521
+ registration and let the owner register afresh; do not send a verification
522
+ link instead, which would let the owner verify that account and recover it.
523
+
524
+ ## Audience tokens
525
+
526
+ When the daemon has `[tokens]` configured, it signs short-lived tokens that
527
+ let another service verify a session offline against
528
+ `/.well-known/jwks.json`. Your server holds the session, so it asks for them:
529
+
530
+ ```ruby
531
+ minted = client.audience_token(token: session_token, audience: "maps")
532
+ render json: {token: minted.reveal, expires_at: minted.expires_at}
533
+ ```
534
+
535
+ - An audience the kernel does not serve for this namespace raises
536
+ `Strongroom::InvalidRequest`; an ended session raises `Strongroom::Unauthorized`.
537
+ - The token never outlives the session, and nothing is stored: a logged-out
538
+ session mints no more.
539
+ - `Strongroom::AudienceToken` is redacted in `inspect`, YAML and JSON; only
540
+ `reveal` returns the bearer value.
484
541
 
485
542
  ## Running the daemon
486
543
 
@@ -11,11 +11,15 @@ module Strongroom
11
11
  CURSOR = /\A[A-Za-z0-9_-]{34}\z/
12
12
  IDENTITY_STATES = %w[Unverified Verified Disabled].freeze
13
13
  EVENT_TYPES = %w[Provision Register RegistrationCancel VerificationIssue IdentityVerify PasswordHashUpgrade
14
- PasswordReplace Revoke RecoveryIssue RecoveryComplete PasswordChange].freeze
14
+ PasswordReplace Revoke RecoveryIssue RecoveryComplete PasswordChange AccountSuspend AccountReinstate].freeze
15
15
  LOGIN = {"session_id" => :uuid, "user_id" => :uuid, "expires_at" => :timestamp,
16
16
  "identity_verified" => :boolean}.freeze
17
17
  METADATA = LOGIN.merge("org_id" => :uuid, "app_id" => :uuid).freeze
18
18
  SERVICE_KEY_HEADER = "X-Strongroom-Service-Key"
19
+ AUDIENCE = /\A[a-z][a-z0-9._-]{0,63}\z/
20
+ COMPACT_JWS = /\A[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\z/
21
+ AUDIENCE_TOKEN = {"token" => :string, "token_type" => :string, "audience" => :string,
22
+ "expires_at" => :timestamp}.freeze
19
23
  attr_reader :endpoint, :issuer, :namespace, :org_id, :app_id, :cookie_name, :service_endpoint
20
24
 
21
25
  def initialize(endpoint:, issuer:, namespace:, org_id:, app_id:, cookie_base: "__Host-strongroom_session",
@@ -120,6 +124,20 @@ module Strongroom
120
124
  nil
121
125
  end
122
126
 
127
+ def audience_token(token:, audience:)
128
+ raise InvalidRequest, "invalid audience" unless audience.is_a?(String) && audience.match?(AUDIENCE)
129
+ response = request(:post, "token", token: Token.coerce(token), body: JSON.generate(audience: audience),
130
+ refusable: true)
131
+ values = object(response, AUDIENCE_TOKEN)
132
+ minted = values["token"]
133
+ unless values["token_type"] == "Bearer" && values["audience"] == audience &&
134
+ minted.bytesize <= 8192 && minted.match?(COMPACT_JWS)
135
+ raise ProtocolError, "invalid token response"
136
+ end
137
+ raise Unauthorized, "session expired" unless values["expires_at"] > Time.now
138
+ AudienceToken.new(value: minted, audience: audience, expires_at: values["expires_at"])
139
+ end
140
+
123
141
  def discard(token:)
124
142
  logout(token: token)
125
143
  true
@@ -181,8 +199,11 @@ module Strongroom
181
199
  # this namespace; earlier recovery links of that address stop working. The
182
200
  # browser completes it: POST {"token", "password"} to
183
201
  # `/accounts/<namespace>/recovery` on the kernel's public listener. Raises
184
- # `NotFound` when no usable account holds the address: answer your users
185
- # the same way either way.
202
+ # `NotFound` when no usable account holds the address, and
203
+ # `IdentityUnverified` when the address was registered but never verified:
204
+ # whoever registered it may not own it, so cancel that registration and let
205
+ # the owner register afresh rather than recover it. Answer your users the
206
+ # same way in every case.
186
207
  def issue_recovery(identity:)
187
208
  raise InvalidRequest, "identity must be a string" unless identity.is_a?(String)
188
209
  body = JSON.generate(identity_kind: "email", identity: identity)
@@ -195,6 +216,76 @@ module Strongroom
195
216
  raise InvalidRequest, "invalid recovery payload", cause: nil
196
217
  end
197
218
 
219
+ # Suspends the account of `user_id` in this namespace's org: every session
220
+ # it holds there ends, its verification and recovery links stop working,
221
+ # and it authenticates nowhere in the org until `reinstate`. Raises
222
+ # `NotFound`, `AccountDisabled`, or `Busy` while one of its sessions is
223
+ # being rotated or logged out (retry).
224
+ def suspend(user_id:)
225
+ account_change("suspensions", user_id, "Suspended")
226
+ end
227
+
228
+ # Lifts a suspension. The sessions and links it ended stay ended.
229
+ def reinstate(user_id:)
230
+ account_change("reinstatements", user_id, "Active")
231
+ end
232
+
233
+ # Ends every live session of `user_id` in this namespace's org, whatever
234
+ # its account's state, and returns how many ended. `Busy` as for `suspend`.
235
+ def revoke_sessions(user_id:)
236
+ raise InvalidRequest, "user_id must be a canonical UUID" unless canonical_uuid?(user_id)
237
+ response = service_request(:post, "revocations", body: JSON.generate(user_id: user_id), statuses: [200])
238
+ object(response, {"revoked_sessions" => :count})["revoked_sessions"]
239
+ end
240
+
241
+ # Imports one account with a pre-hashed password (bcrypt or Argon2id), keyed
242
+ # by your `source` and `external_id`, as `strongroom-admin provision` does;
243
+ # the namespace needs `import = true`. Every state is explicit: the kernel
244
+ # refuses MFA and unverified identities. Replaying the same import returns
245
+ # its receipt (`created: false`); a changed one raises `BindingConflict`,
246
+ # an address another account holds `IdentityTaken`.
247
+ def import_account(source:, external_id:, identity:, password_hash:, account_state:, grant_state:,
248
+ identity_state:, credential_state:, mfa_required:, identity_kind: "email")
249
+ fields = {source: source, external_id: external_id, identity_kind: identity_kind, identity: identity,
250
+ account_state: account_state, grant_state: grant_state, identity_state: identity_state,
251
+ credential_state: credential_state, password_hash: password_hash}
252
+ unless fields.values.all?(String) && [true, false].include?(mfa_required)
253
+ raise InvalidRequest, "import fields must be strings and mfa_required a boolean"
254
+ end
255
+ body = JSON.generate(fields.merge(mfa_required: mfa_required))
256
+ raise InvalidRequest, "import request too large" if body.bytesize > 16_384
257
+ response = service_request(:post, "imports", body: body, statuses: [200, 201])
258
+ values = object(response, {"user_id" => :uuid, "identity_id" => :uuid, "credential_id" => :uuid})
259
+ Import.new(user_id: values["user_id"], identity_id: values["identity_id"],
260
+ credential_id: values["credential_id"], created: response.status == 201)
261
+ rescue JSON::GeneratorError
262
+ raise InvalidRequest, "invalid import payload", cause: nil
263
+ end
264
+
265
+ # Replaces the password of the account an import bound to `source` and
266
+ # `external_id` with `password_hash`, but only while its active credential
267
+ # still holds `expected_password_hash`, the hash you imported or last
268
+ # replaced. Once the kernel owns the password (a login upgraded its hash, a
269
+ # recovery or password change replaced it) this raises `CredentialChanged`
270
+ # and changes nothing. Its sessions end with the old credential.
271
+ def replace_imported_password(source:, external_id:, expected_password_hash:, password_hash:)
272
+ fields = {source: source, external_id: external_id, expected_password_hash: expected_password_hash,
273
+ password_hash: password_hash}
274
+ raise InvalidRequest, "replacement fields must be strings" unless fields.values.all?(String)
275
+ body = JSON.generate(fields)
276
+ raise InvalidRequest, "replacement request too large" if body.bytesize > 16_384
277
+ response = service_request(:post, "imports/password", body: body, statuses: [200])
278
+ values = object(response, {"status" => :string, "user_id" => :uuid, "identity_id" => :uuid,
279
+ "credential_id" => :uuid, "revoked_credential_id" => :uuid_or_nil})
280
+ unless (values["status"] == "replaced") == !values["revoked_credential_id"].nil? &&
281
+ %w[replaced unchanged].include?(values["status"])
282
+ raise ProtocolError, "invalid service response"
283
+ end
284
+ PasswordReplacement.new(**values.transform_keys(&:to_sym))
285
+ rescue JSON::GeneratorError
286
+ raise InvalidRequest, "invalid replacement payload", cause: nil
287
+ end
288
+
198
289
  # One page of the namespace's event feed, in commit-safe order.
199
290
  def events(after: nil, limit: 100)
200
291
  unless (after.nil? || (after.is_a?(String) && after.match?(CURSOR))) &&
@@ -214,6 +305,16 @@ module Strongroom
214
305
 
215
306
  private
216
307
 
308
+ def account_change(suffix, user_id, state)
309
+ raise InvalidRequest, "user_id must be a canonical UUID" unless canonical_uuid?(user_id)
310
+ response = service_request(:post, suffix, body: JSON.generate(user_id: user_id), statuses: [200])
311
+ schema = {"state" => :string, "changed" => :boolean}
312
+ schema["revoked_sessions"] = :count if state == "Suspended"
313
+ values = object(response, schema)
314
+ raise ProtocolError, "invalid service response" unless values["state"] == state
315
+ AccountChange.new(state: state, changed: values["changed"], revoked_sessions: values.fetch("revoked_sessions", 0))
316
+ end
317
+
217
318
  def configure_service(endpoint, key, transport)
218
319
  if endpoint.nil? && key.nil? && transport.nil?
219
320
  @service_endpoint = @service_key = @service_transport = nil
@@ -278,7 +379,7 @@ module Strongroom
278
379
  value.is_a?(String) && value.match?(UUID) && value != "00000000-0000-0000-0000-000000000000"
279
380
  end
280
381
 
281
- def request(method, suffix, token: nil, body: nil, status: 200)
382
+ def request(method, suffix, token: nil, body: nil, status: 200, refusable: false)
282
383
  headers = {"Accept" => "application/json", "Accept-Encoding" => "identity",
283
384
  "Cache-Control" => "no-store", "X-Strongroom-Request" => "1"}
284
385
  headers["Content-Type"] = "application/json" if body
@@ -286,6 +387,7 @@ module Strongroom
286
387
  response = @transport.call(method, "/accounts/#{namespace}/#{suffix}", headers: headers, body: body)
287
388
  bounded!(response)
288
389
  case response.status
390
+ when 400 then raise InvalidRequest, "request refused" if refusable
289
391
  when 401 then raise Unauthorized, "authentication failed"
290
392
  when 403 then raise ProtocolError, "authentication request refused by service policy"
291
393
  when 409 then conflict!(response)
@@ -340,7 +442,9 @@ module Strongroom
340
442
  when "identity_disabled" then raise IdentityDisabled, "identity is disabled"
341
443
  when "cursor_ahead" then raise CursorAhead, "feed cursor is ahead of the kernel's database"
342
444
  when "identity_unverified" then raise IdentityUnverified, "identity is not verified"
343
- when "credential_changed" then raise CredentialChanged, "session predates the identity's password"
445
+ when "credential_changed" then raise CredentialChanged, "the identity's password credential changed"
446
+ when "account_disabled" then raise AccountDisabled, "account is disabled"
447
+ when "no_active_credential" then raise NoActiveCredential, "account has no active password"
344
448
  else raise ProtocolError, "invalid service response"
345
449
  end
346
450
  end
@@ -398,6 +502,7 @@ module Strongroom
398
502
  when :uuid then canonical_uuid?(value)
399
503
  when :boolean then value == true || value == false
400
504
  when :uuid_or_nil then value.nil? || canonical_uuid?(value)
505
+ when :count then value.is_a?(Integer) && value >= 0
401
506
  else value.is_a?(String)
402
507
  end
403
508
  end
@@ -21,9 +21,17 @@ module Strongroom
21
21
  class IdentityUnverified < Conflict; end
22
22
 
23
23
  # A password change from a session issued with a password the identity no
24
- # longer logs in with: sign in again, then change it. Nothing changed.
24
+ # longer logs in with: sign in again, then change it. For an imported
25
+ # password replacement: the kernel's credential no longer holds the expected
26
+ # hash, so the kernel owns that password now. Nothing changed.
25
27
  class CredentialChanged < Conflict; end
26
28
 
29
+ # A suspension or reinstatement of an account that is disabled, which is final.
30
+ class AccountDisabled < Conflict; end
31
+
32
+ # An imported password replacement for an account without an active password.
33
+ class NoActiveCredential < Conflict; end
34
+
27
35
  # The feed cursor names a point the kernel's database has not reached (it was
28
36
  # restored, failed over or copied): drop the cursor and read from the start.
29
37
  class CursorAhead < Conflict; end
@@ -65,6 +65,21 @@ module Strongroom
65
65
  client.events(after: after, limit: limit)
66
66
  end
67
67
 
68
+ # Suspends the user's account in the namespace's org, ending its sessions
69
+ # and links; needs only the service key.
70
+ def suspend(user_id:)
71
+ client.suspend(user_id: user_id)
72
+ end
73
+
74
+ def reinstate(user_id:)
75
+ client.reinstate(user_id: user_id)
76
+ end
77
+
78
+ # Ends every live session of the user in the namespace's org.
79
+ def revoke_sessions(user_id:)
80
+ client.revoke_sessions(user_id: user_id)
81
+ end
82
+
68
83
  def resolve(session)
69
84
  subject = client.subject(session)
70
85
  record = @resolver.call(subject)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Strongroom
4
4
  module Rails
5
- VERSION = "0.3.0" # x-release-please-version
5
+ VERSION = "0.5.0" # x-release-please-version
6
6
  end
7
7
  end
@@ -10,6 +10,20 @@ module Strongroom
10
10
  # changed nothing; `identity_state` is the identity's current state.
11
11
  Registration = Data.define(:user_id, :identity_id, :identity_state, :created)
12
12
 
13
+ # What a suspension or reinstatement did: the account's `state` now
14
+ # ("Suspended" or "Active"), whether this call `changed` it, and how many
15
+ # sessions a suspension ended (0 for a reinstatement or a repeat).
16
+ AccountChange = Data.define(:state, :changed, :revoked_sessions)
17
+
18
+ # An import's receipt. `created` is false for an exact replay, which changed
19
+ # nothing.
20
+ Import = Data.define(:user_id, :identity_id, :credential_id, :created)
21
+
22
+ # A replaced imported password. `status` is "replaced" (the credential
23
+ # `revoked_credential_id` was revoked for `credential_id`) or "unchanged"
24
+ # (the active credential held that hash already; `revoked_credential_id` nil).
25
+ PasswordReplacement = Data.define(:status, :user_id, :identity_id, :credential_id, :revoked_credential_id)
26
+
13
27
  # One account event from the namespace's feed. `meta` is a frozen Hash of
14
28
  # non-secret IDs (session, credential, token).
15
29
  Event = Data.define(:id, :type, :user_id, :identity_id, :at, :meta)
@@ -37,6 +51,32 @@ module Strongroom
37
51
  end
38
52
  end
39
53
 
54
+ class AudienceToken
55
+ attr_reader :audience, :expires_at
56
+
57
+ def initialize(value:, audience:, expires_at:)
58
+ @value, @audience, @expires_at = value.dup.freeze, audience.dup.freeze, expires_at
59
+ freeze
60
+ end
61
+
62
+ def reveal = @value
63
+ def inspect = "#<Strongroom::AudienceToken audience=#{audience} expires_at=#{expires_at.iso8601} token=[FILTERED]>"
64
+ alias to_s inspect
65
+ def pretty_print(printer) = printer.text(inspect)
66
+
67
+ def as_json(*)
68
+ raise TypeError, "audience tokens must not be serialized"
69
+ end
70
+
71
+ def marshal_dump
72
+ raise TypeError, "audience tokens must not be serialized"
73
+ end
74
+
75
+ def encode_with(coder)
76
+ coder.map = {"audience" => audience, "token" => "[FILTERED]"}
77
+ end
78
+ end
79
+
40
80
  # A link's secret and its expiry. Put the token in the URL fragment of a link
41
81
  # to your own page, which posts it to the kernel; nothing here is safe to log
42
82
  # or serialize.
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.3.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seuros