strongroom-rails 0.4.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: 5561c0010955953673794759017eb0f3683d838d60dd70ed09ae88f185954717
4
- data.tar.gz: 0d620abade30695c4779dc8e123c9444b4ff723904e3bc19bd903985f1f47d53
3
+ metadata.gz: eff1ffd8da620844d98a61ce2bdea990af1c2466269c2b4684141016b5a50aea
4
+ data.tar.gz: 39cefca8d430c6de20198811d1a2bda0fb330d53f3e151a71eeac26b109a68e2
5
5
  SHA512:
6
- metadata.gz: aa14aa3c3c14336f886876097bb85afb3c56332583567eadbf88b3839abbf518e8af4841a80023d0085ad5e7df6b58a9dff0962c875b0a028751dd4ff6c42046
7
- data.tar.gz: 333bce6b18f73ec77edbe98645668cd40bcbcaa3443eff5e501706c4e915aee4c18c1808298022222622bf4708cf80f21dd4f6e0923aaa0fc03aded6e51dac61
6
+ metadata.gz: 30c068a451c3a097895d237977d4224772cab793b294f26afd666c377ee6ee2f6ec9928a0babea6627d932ad23f8d46a1bbdf0d0ec01eb51a2a60f1024bd7214
7
+ data.tar.gz: efa6f25d3220d2651509b4de8a73a8e64ff3f0c053c1fe76a8b824b70ef93731bb8d96149025d29dad35eadc38dd9b233a95b8b6d9d585d716ec85170e41c179
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
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
+
3
10
  ## [0.4.0](https://github.com/seuros/strongroom/compare/strongroom-rails-v0.3.0...strongroom-rails-v0.4.0) (2026-10-26)
4
11
 
5
12
 
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.
@@ -521,6 +521,24 @@ for that `external_id`). On `Strongroom::IdentityUnverified`, cancel that
521
521
  registration and let the owner register afresh; do not send a verification
522
522
  link instead, which would let the owner verify that account and recover it.
523
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.
541
+
524
542
  ## Running the daemon
525
543
 
526
544
  This gem is only the client: it ships no binary and needs none to install. The
@@ -16,6 +16,10 @@ module Strongroom
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
@@ -361,7 +379,7 @@ module Strongroom
361
379
  value.is_a?(String) && value.match?(UUID) && value != "00000000-0000-0000-0000-000000000000"
362
380
  end
363
381
 
364
- def request(method, suffix, token: nil, body: nil, status: 200)
382
+ def request(method, suffix, token: nil, body: nil, status: 200, refusable: false)
365
383
  headers = {"Accept" => "application/json", "Accept-Encoding" => "identity",
366
384
  "Cache-Control" => "no-store", "X-Strongroom-Request" => "1"}
367
385
  headers["Content-Type"] = "application/json" if body
@@ -369,6 +387,7 @@ module Strongroom
369
387
  response = @transport.call(method, "/accounts/#{namespace}/#{suffix}", headers: headers, body: body)
370
388
  bounded!(response)
371
389
  case response.status
390
+ when 400 then raise InvalidRequest, "request refused" if refusable
372
391
  when 401 then raise Unauthorized, "authentication failed"
373
392
  when 403 then raise ProtocolError, "authentication request refused by service policy"
374
393
  when 409 then conflict!(response)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Strongroom
4
4
  module Rails
5
- VERSION = "0.4.0" # x-release-please-version
5
+ VERSION = "0.5.0" # x-release-please-version
6
6
  end
7
7
  end
@@ -51,6 +51,32 @@ module Strongroom
51
51
  end
52
52
  end
53
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
+
54
80
  # A link's secret and its expiry. Put the token in the URL fragment of a link
55
81
  # to your own page, which posts it to the kernel; nothing here is safe to log
56
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.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seuros